Object-Oriented Controllers

Showing 1-5 of 5 messages
Object-Oriented Controllers Avdi Grimm 4/30/12 6:28 PM
Several people have asked me what what I think truly object-oriented
controllers would look like. I haven't had time to write down my
ideas, but I feel like now I don't have to because Jon Leighton has
nailed it:


I've seen a few whacks at this problem involving things like DSLs for
setting up different contexts for different actions, but they rubbed
me the wrong way. If two different actions require two different sets
of helper methods, they should be two different objects.

Check out the README, it makes a great case for representing separate
actions as separate objects, possibly sharing common inheritance or

I'm sure some people will be repelled by the verbosity of it, but I
suspect that it wouldn't be hard to apply some minimal DSL sugar which
preserved the semantics while cutting down on the need to type "class"
over and over.

Anyway, I'm excited to see this.

Avdi Grimm

I only check email twice a day. to reach me sooner, go to
Re: Object-Oriented Controllers Felix Schäfer 5/1/12 1:05 AM
On Tue, May 1, 2012 at 3:28 AM, Avdi Grimm <avdi....@gmail.com> wrote:
> Jon Leighton has
> nailed it:
> https://github.com/jonleighton/focused_controller

IIRC he presented them at the Railsberry, I'll post the link to the
video here as soon it's available.

Re: Object-Oriented Controllers Kris Leech 2/13/13 2:50 PM
I've been playing with using focused_controller tonight, its been a nice experience. Because actions are classes, not methods, it means that the listener passed to a service object is not a controller exposing public callback methods, which are potentially mappable from routing.

Re: Object-Oriented Controllers James Deville 2/14/13 2:54 PM
I'd be interested in knowing people's thoughts on the Objectify pattern that James Golick uses/promotes with https://github.com/bitlove/objectify and http://jamesgolick.com/2012/5/22/objectify-a-better-way-to-build-rails-applications.html. I actually found that to be really appealing as it feels like it promotes more domain objects than "action" objects. I haven't had a chance to try either of them yet, so I don't know how the feel to use :|

Re: Object-Oriented Controllers Perry Smith 2/18/13 9:15 AM
I need to read and play with these new ideas.

The thing I'm doing in my latest project is a half-ass morph of some of these concepts.  The reason for the morph is mostly due to growing into the solution rather than starting out with a new style directly.

I have a normal Rails controllers but the actions are trivial:

  def show
    respond_with(create_presenter(:which_fileset, GetWhichFilesets.new(params)))

The presenter is a Keynote presenter (which has been discussed in this forum) and GetWhichFilesets is a class in app/actions.  The app/actions and app/entities are concepts stolen from Obvious.  I don't have any app/entities yet.

At the top of the controller I have

respond_to :html, :json 

and then put the to_json inside the presenter.  I really want each URL to be able to respond via HTML and via JSON.

So far, this is working out well for me.

The one "oh dear" I had is realizing that the action classes are verbs and not nouns.  One person on the net commented that when he does that, it tends to cause those classes to really have a focused single responsibility which seems to be true for me as well.  For me, it is easier to ask "is this part of <verb>?" than it is to ask "is this part of <noun>?"

You received this message because you are subscribed to the Google Groups "Objects on Rails" group.
To unsubscribe from this group and stop receiving emails from it, send an email to objects-on-rai...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.