This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function init() { | |
| var allHTMLTags=document.getElementsByTagName('td'); | |
| getElem('id','notMandatoryRow',0).style.display="none"; | |
| var allHTMLTags=document.getElementsByTagName('td'); | |
| for (i=0; i<allHTMLTags.length; i++) { | |
| if (allHTMLTags[i].className=="label") { | |
| var e = allHTMLTags[i].innerHTML; | |
| if(e.match(/\*/) != null) { | |
| allHTMLTags[i].innerHTML = e.replace(/\*/,""); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| validates_each :iban do | record, attr, value | | |
| record.errors.add attr, 'IBAN is mandatory' and next if value.blank? | |
| # IBAN code should start with country code (2letters) | |
| record.errors.add attr, 'Country code is missing from the IBAN code' and next unless value.to_s =~ /^[A-Z]{2}/i | |
| iban = value.gsub(/[A-Z]/) { |p| (p.respond_to?(:ord) ? p.ord : p[0]) - 55 } | |
| record.errors.add attr, 'Invalid IBAN format' unless (iban[6..iban.length-1].to_s+iban[0..5].to_s).to_i % 97 == 1 | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "recipe": { | |
| "id": "", | |
| "category": "eggs", | |
| "nerd_level": 1, | |
| "photo_url": "", | |
| "preparation": "", | |
| "name": "fried egg with applesauce and mashed potatoes", | |
| "created_at": "2011-08-22", | |
| "created_by": "koos", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class UsersController < ApplicationController::Base | |
| def index | |
| @users = User.all | |
| respond_to do |format| | |
| format.html | |
| format.xml { render :xml => @users } | |
| format.json { render :json => @users } | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class UsersController < ApplicationController::Base | |
| respond_to :html, :xml, :json | |
| def index | |
| respond_with(@users = User.all) | |
| end | |
| def create | |
| @user = User.create(params[:user]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| render :json => { :success => true, :user => @user.as_json(:only => [:email]) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # app/app.rb | |
| get "/posts", :provides => [:json, :xml] do | |
| @user = current_user | |
| @posts = Post.order("id DESC") | |
| render "posts/index" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # app/views/posts/index.rabl | |
| collection @posts | |
| attributes :id, :title, :subject | |
| child(:user) { attributes :full_name } | |
| node(:read) { |post| post.read_by?(@user) } | |
| The result of this is a JSON (or XML) looking like this: | |
| [{ post : | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Api::UsersController < ApiController | |
| def show | |
| respond_with(object_as_json(User.find_by_slug(params[:id]))) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "type": "object", | |
| "title": "user", | |
| "description": "a user", | |
| "properties": { | |
| "id": { | |
| "type": "string", | |
| "description": "The User Id", | |
| "identity": true, | |
| "required": true, |