[LRUG] Encapsulation/Responsibility delegation and API versioning.

Andrew Stewart boss at airbladesoftware.com
Mon Aug 22 08:27:28 PDT 2011


On 22 Aug 2011, at 17:16, Ian Leitch wrote:
> The smell that's now beginning to emerge is that controllers are
> getting fat with protected helper methods that build data structures
> for conversion into JSON. Normally I'd push these down into the
> model/some class, but like I said, I need API versions to remain
> self-contained.
> 
> My initial thought was to suffix model methods with the API version,
> i.e attributes_for_json_api_v1 but that'll soon result in fat models,
> which I dont want.
> 
> What solutions have other people used for this problem?
> 
> 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!

Perhaps something like this?

https://github.com/jcasimir/draper

(I haven't yet tried it myself.)

Cheers,
Andy Stewart

-------
http://airbladesoftware.com



More information about the Chat mailing list