Created
October 14, 2012 01:07
-
-
Save steveklabnik/3886837 to your computer and use it in GitHub Desktop.
Some thoughts on real ViewModels for Draper 2.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cells is about multiple controllers and views per page. This is just one.