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 <
frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
>
> On Aug 17, 1:59 am, Cainus
<cai...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
>
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> 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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.