You can add the following helper method to ApplicationHelper :
def current_layout (controller.send :_layout).inspect.split("/").last.gsub(/.html.erb/,"") end
And you can call it appropriately in the set_meta_tags method. Something like,
def set_meta_tags title = (current_layout != "application") ? "#{current_layout} ::" : false set_meta title: "#{layout} #{setting(:site, :title)}", description: setting(:site, :description) end
Note:
.inspect gives me the name of the layout with its relative path.
.split("/").last will remove the relative path and return only the layout name (with extension).
.gsub(/.html.erb/) removes part of the layout extension. You may need to configure extension based on your template engine, for example. In the case of using Haml .html.haml .
My decision
From the chat with Kirti, it seems that my forgetting to mention that we manually set out the layout was a big deal. This will work if you manually set your layout:
#app/helpers/application_helper.rb def current_layout self.send :_layout end def set_meta_tags title = (current_layout != "application") ? "#{current_layout.titleize} :: " : "" set_meta title: title + setting(:site, :title), description: setting(:site, :description) end
Kirti thorat
source share