Rails, passing a variable from the controller to the application layout

I have the following:

In my controller

  def gettingstarted
    @title = "Getting Started"
        respond_to do |format|
      format.html { render :layout => true, :showLeftNav => false }
    end
  end

In my default application layout file, Layouts /application.html.erb :

<% showLeftNav = true if local_assigns[:showLeftNav].nil? %>
<body style="<% if showLeftNav == false %>background:none !important;<% end %>">

Am I passing showLeftNav incorrectly from the controller to the layout?

+3
source share
2 answers

Why not define this as an instance variable, for example @title? That way you can just use it in the view, as well as its default value.

+10
source

local_assigns (ActionView) . . , , this Public Instance, .

0

Source: https://habr.com/ru/post/1780359/


All Articles