lekha p. wrote in post #1106474:> Please Help,
>
> Hi can anybody show me some simple code which shows how using json in
> Rails application.
Example 1: Rails bult-in JSON support:
1. rails generate scaffold User first_name:string last_name:string
2. rake db:migrate
3. rails s
4. Goto: http://localhost:3000/users/new
5. Create some users
6. curl http://localhost:3000/users.json
For the code look at app/controllers/users_controller.rb
Example 2: JSON from Array
$ rails console
my_arr = %w{a list of some words in an array}
puts my_arr.to_json
Example 3: JSON from Hash
$ rails console
my_hash = {first: "Hello World", second: 10, third: Time.now}
puts my_hash.to_json
Example 4: RABL
For more sophisticated JSON needs take a look at examples in the RABL
gem:
https://github.com/nesquena/rabl
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.