Module: Livery::Controller::ClassMethods
- Defined in:
- lib/livery/controller.rb
Instance Method Summary collapse
-
#use_presenters! ⇒ Object
Overrides AbstractController#view_assigns to return presenters set with the
present
method.
Instance Method Details
#use_presenters! ⇒ Object
Overrides AbstractController#view_assigns to return presenters set with the present
method.
When you call this method in a controller class, instance variables set in actions will no longer be shared with views.
Examples
# app/controllers/posts_controller.rb
class PostController < ApplicationController
include Livery::Controler
use_presenters!
def show
@post = Post.find(params[:id])
present(post_presenter: @post)
end
end
In this example, the instance variable @post will not be shared with the view. Instead, the present
method will create a presenter-wrapped object available as @post_presenter in the view.
31 32 33 34 35 |
# File 'lib/livery/controller.rb', line 31 def use_presenters! define_method "view_assigns" do @_presenters || {} end end |