Monday, June 3, 2024
42
rated 0 times [  44] [ 2]  / answers: 1 / hits: 15785  / 15 Years ago, thu, february 25, 2010, 12:00:00

Might be obvious, but still I'm lacking here of the basic knowledge.



So inside controllers, can both be used, or is it always Javascript, so both are the same?


More From » ruby-on-rails

 Answers
4

In Rails 3.1 the only difference I can spot is that the if formatter is js, then the answer is sent as plain text. If it is json then it is encoded as json.



if format.json



format.json {
render :json => @accounts.map(&:attributes)
}


server send:



data:application/json;base64,


if format.js



format.js {
render :json => @accounts.map(&:attributes)
}


server send:



[{id:33,email:[email protected]}]

[#97489] Monday, February 22, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tristab

Total Points: 735
Total Questions: 106
Total Answers: 96

Location: Grenada
Member since Sun, Dec 20, 2020
4 Years ago
tristab questions
Sat, Sep 25, 21, 00:00, 3 Years ago
Sun, Jan 31, 21, 00:00, 3 Years ago
Wed, Dec 2, 20, 00:00, 4 Years ago
Fri, Oct 23, 20, 00:00, 4 Years ago
;