Module: Oprah::ControllerHelpers
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/oprah/controller_helpers.rb
Overview
Helpers that will be mixed into ‘ActionController::Base` and `ActionMailer::Base` by the Railtie.
Defined Under Namespace
Classes: ViewContextProxy
Instance Method Summary collapse
-
#oprah_view_context ⇒ ActionView::Base
The view context automatically passed to objects presented from this controller.
-
#oprah_view_context=(view_context) ⇒ ActionView::Base
Assigns the view context returned from #oprah_view_context.
-
#present(*args, **kwargs, &block) ⇒ Object
Presents a single object.
-
#present_many(*args, **kwargs, &block) ⇒ Object
Presents a collection of objects.
-
#view_context ⇒ ActionView::Base
Returns an instance of a view class and sets the current view context returned by #oprah_view_context.
Instance Method Details
#oprah_view_context ⇒ ActionView::Base
The view context automatically passed to objects presented from this controller.
You can override this method pass a custom view context to all presented objects from the controller scope.
71 72 73 |
# File 'lib/oprah/controller_helpers.rb', line 71 def oprah_view_context @oprah_view_context || view_context end |
#oprah_view_context=(view_context) ⇒ ActionView::Base
Assigns the view context returned from #oprah_view_context.
You can override this method pass a custom view context to all presented objects from the controller scope.
84 85 86 |
# File 'lib/oprah/controller_helpers.rb', line 84 def oprah_view_context=(view_context) @oprah_view_context = view_context end |
#present(*args, **kwargs, &block) ⇒ Object
Presents a single object.
Will pass the view context returned from #oprah_view_context to the presenter by default. This can be overridden.
41 42 43 44 45 46 47 |
# File 'lib/oprah/controller_helpers.rb', line 41 def present(*args, **kwargs, &block) kwargs = { view_context: oprah_view_context_proxy }.merge(kwargs) Presenter.present(*args, **kwargs, &block) end |
#present_many(*args, **kwargs, &block) ⇒ Object
Presents a collection of objects.
Will pass the view context returned from #oprah_view_context to the presenter by default. This can be overridden.
55 56 57 58 59 60 61 |
# File 'lib/oprah/controller_helpers.rb', line 55 def present_many(*args, **kwargs, &block) kwargs = { view_context: oprah_view_context_proxy }.merge(kwargs) Presenter.present_many(*args, **kwargs, &block) end |
#view_context ⇒ ActionView::Base
Returns an instance of a view class and sets the current view context returned by #oprah_view_context.
If you override this method in your controller ensure you keep Oprah’s view context updated using #oprah_view_context=.
98 99 100 |
# File 'lib/oprah/controller_helpers.rb', line 98 def view_context self.oprah_view_context = super end |