Created
November 2, 2010 17:46
-
-
Save erubboli/659994 to your computer and use it in GitHub Desktop.
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
| User.include_root_in_json = true | |
| User.first.to_json(:only => [:screen_name,:id]) | |
| #=> {"user":{"id":1,"screen_name":"test"}} | |
| User.include_root_in_json = false | |
| User.first.to_json(:only => [:screen_name,:id]) | |
| #=> {"id":1,"screen_name":"test"} |
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.json { render :json => @users } | |
| end | |
| 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
| render :json => @users.to_json, :callback => params[:callback] | |
| #=> jsonp1288721752692(["user1", "user2"]); |
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, :json | |
| def index | |
| respond_with(@users = User.all) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment