Module: Reins::ViewHelpers
- Defined in:
- lib/reins/view_helpers.rb
Instance Method Summary collapse
-
#call_reins_controller ⇒ Object
Helper for use in js.erb templates to automatically call the reins controller and action that matches the current rails controller and action name.
-
#reins_script_tag(**html_attributes) ⇒ Object
Helper that creates a <script> tag insertable into HTML templates to set the reins controller and action to the current rails controller and action name.
-
#update_reins_controller ⇒ Object
Helper that emits JS code to set the reins controller and action to the current rails controller and action name.
Instance Method Details
#call_reins_controller ⇒ Object
Helper for use in js.erb templates to automatically call the reins controller and action that matches the current rails controller and action name.
- Returns
-
The javascript code that will perform the necessary actions.
31 32 33 |
# File 'lib/reins/view_helpers.rb', line 31 def call_reins_controller "#{ update_reins_controller }r.call_js_controller();".html_safe end |
#reins_script_tag(**html_attributes) ⇒ Object
Helper that creates a <script> tag insertable into HTML templates to set the reins controller and action to the current rails controller and action name.
- Returns
-
The javascript code that will perform the necessary actions.
8 9 10 11 12 |
# File 'lib/reins/view_helpers.rb', line 8 def reins_script_tag(**html_attributes) attrs = html_attributes.map { |k, v| %(#{k}="#{v}") }.join(' ') "<script #{attrs}>#{ update_reins_controller }</script>".html_safe end |
#update_reins_controller ⇒ Object
Helper that emits JS code to set the reins controller and action to the current rails controller and action name.
- Returns
-
The javascript code that will perform the necessary actions.
19 20 21 22 23 |
# File 'lib/reins/view_helpers.rb', line 19 def update_reins_controller "r.controller = '#{ params[:controller] }'; r.action = '#{ params[:action] }'; r.params = #{ @reins_params.to_json };".html_safe end |