On 23/08/2011, at 6:37 AM, Steve Hoeksema wrote:

>> I'm almost considering a layer in between my controllers and models,
>> almost like a presentation layer from model to controller. Mixins
>> could help here... perhaps something like this?
>> https://gist.github.com/1162618
>> Could get messy if the controller uses a large number of models?
>> Thoughts welcome!
> 
> I tried using built-in views but it seemed like more trouble than it was 
> worth, particularly to render either a JSON object or an array of JSON 
> objects without hacks or duplicating code.

IMHO, a JSON (or XML) representation of your data is no less a "view" than an 
HTML representation.  I think you guys (Ian and Steve) are taking the right 
approach by de-coupling the JSON generation from both controller AND model.

Nathan's already mentioned my "Representative" gem, which was built to address 
exactly this problem, with a FormBuilder-like DSL for extracting properties 
from objects.  It's not necessarily any better than what you suggest, just 
slightly more succinct.

See also: "If you’re using to_json, you’re doing it wrong."
http://engineering.gomiso.com/2011/05/16/if-youre-using-to_json-youre-doing-it-wrong/

-- 
cheers, 
Mike Williams

-- 
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