Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: Controller-specific menu in layout

How do I add a controller-specific menu (or div) inside a general application layout in Rails?

like image 644
alste Avatar asked Dec 27 '22 17:12

alste


1 Answers

method 1: set a variable in that controller

class SomeController
  before_filter :set_to_use_menu

  private

  def set_to_use_menu
    @use_menu = true
  end
end

method 2: determine the controller's name in the layout

<%- if controller_name == "your_controller_name" %>
  <%= render :partial => "the_menu" %>
<%- end %>
like image 157
PeterWong Avatar answered Jan 08 '23 07:01

PeterWong