Hi,

I'm building a web service that will be accessed from a phone.

So what I'm seeing so far is that building json responses seems to be
quite limited (but I think I'm just missing something)

Lets say I have users, and they can have different amounts of types of
debt.  In this case the debt is calculated based on a couple of
different things.  So in order to calculate debt I need to do some
things.

I also might want to return a status message (success/failure) with
each json resonse

I know I can do something like:
render format.json { :json => {:success => true,  :user =>
@user.as_json } }

I can also overwrite as_json in the user model to customize the
output.  I want to have more options than that thouse, since overwrite
as_json is kind of global. I'm imagining having specialized functions
that will return json that has a very different structure than the
model itself.

render format.json { :json => {:success => true,  :user =>
@user.json_for_dropdown } }
render format.json { :json => {:success => true,  :user =>
@user.json_for_invoice } }


Is this possible?  How do I write json_for_X to return json etc? Is
there a better way to do this? Are there templates that can be used
for json like rendering partials?

Thanks

Joe

-- 
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-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to