DEV Community

n350071πŸ‡―πŸ‡΅
n350071πŸ‡―πŸ‡΅

Posted on • Updated on

View & Helper Tips Note

View

πŸ‘ pass a variable into partial

The file app/views/shared/_question.html.erb will be called, and it receives a variable model.

<%= render partial: 'shared/question', locals: { model: @attender } %>

πŸ‘ pass all variables into parcial or use it.

<%= render partial: 'shared/question', locals: local_assigns } %>

πŸ¦„ Another technique

<% unless local_assigns[:hide] %>
  hello
<% end %>

Helper

Setting to use only the helper with same name controller

config/application.rb

config.action_controller.include_all_helpers = false

Use helper method

module MyHelper
  def some
    # do something
  end
end

class SomeController
  include MyHelper
end

πŸ”— Parent Note

Top comments (0)