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