Another option is a decorator library like draper [1]. The README has
a to_json example.

James

[1] https://github.com/jcasimir/draper

On 8 February 2012 12:13, Ben Taylor <[email protected]> wrote:
> Hi roro,
>
> I have a very special purpose API built in Rails for an iPhone and Android
> game. At the moment almost every Model has a custom as_json which does
> things like limit the number of fields returned (for smaller payloads) and
> to include extra relevant information (like data from associations). Some of
> the as_json methods are getting incredibly disgusting as they take modes in
> which they are being viewed (e.g. admin vs client). On top of this many of
> the controller actions build ridiculous Hashes which mix a bunch of
> different models together (especially bad in one particular monolithic
> method, but unfortunately that method has to stay).
>
> So the solution I want to implement is to start rendering JSON Views. JSON
> Views would make a lot of sense for what I'm doing. Especially for the
> monolithic method, it would be amazing to split that up into partials. Is
> there anything which is particularly good for this? Or should I just create
> a bunch of .json.erb files?
>
> Cheers,
>  - Ben
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby or Rails Oceania" 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/rails-oceania?hl=en.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
or Rails Oceania" 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/rails-oceania?hl=en.

Reply via email to