You can also use to_josn method to get the json string. Its built-in method
in rails.
when request arrives at server you can get json data in parameter which you
can fatch by params[:<json root name>]
You can view the whole request ad json in rails by using req.as_json method.


On Wed, Aug 17, 2011 at 1:22 PM, Frederick Cheung <
[email protected]> wrote:

>
>
> On Aug 17, 1:59 am, Cainus <[email protected]> wrote:
> > Hey all... I'm building a RESTful JSON API and I find myself writing
> > this:
> >
> > JSON.parse(request.body.read)
> >
> > ...over and over in every controller action that accepts JSON in the
> > request body (which is a lot of actions).
> >
> > Does rails have a better built-in way to keep the code more DRY?  Or
> > should I solve that somehow myself?
> >
>
> If the content-type is set properly on the request, rails should
> populate params with the parsed json itself.
>
> Fred
> > Thanks,
> >
> > Cainus
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to