Skip to content

Instantly share code, notes, and snippets.

@steveklabnik
Created October 14, 2012 01:07
Show Gist options
  • Save steveklabnik/3886837 to your computer and use it in GitHub Desktop.
Save steveklabnik/3886837 to your computer and use it in GitHub Desktop.
Some thoughts on real ViewModels for Draper 2.0
class SomeController < AC::Base
def show
foo = Foo.first
bar = Bar.first
show_model = ShowViewModel.new(foo, bar)
render show_model
end
end
# the view would have exactly one ivar defined, @model. it'd contain the same thing as show_model. No other ivars would be exported.
# by defualt, this would still render app/views/somes/show.html.erb, but you could override it:
class ShowViewModel < Draper::ViewModel
def template_location
"foo/bar"
end
end
# this would then render app/views/foo/bar.html.erb
@stevenharman
Copy link

On a related, but exactly the same, note, I've been "presenter-izing" Draper models lately. Seems to work okay, but I'd image we could come up with a clean API to make it more simple. https://gist.github.com/3887381

@kristianmandrup
Copy link

Why not just use Cells or Apotomo widgets for this!? I plan to use Focused Controller, Draper and Cells/Apotomo in combintion myself. Perhaps even with decent exposure. A beautiful, encapsulated fully OO approach as I see it. We just need a few full examples of this stack in action... no need to reinvent the whole thing again and again IMO.

@steveklabnik
Copy link
Author

Cells is about multiple controllers and views per page. This is just one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment