I have methods that set a title for the browser and for the page itself. On my Devise pages I would like to set these two methods but am not sure how to.
My Code:
helpers/application_helper
def title # for entire application
base_title = "Testing"
if @title.nil?
base_title
else
"#{base_title} - #{@title}"
end
end
def page_title # for page header partial
"#{@page_title}"
end
views/layouts/application
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<%= csrf_meta_tag %>
<%= favicon_link_tag %>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
</head>
<body>
<div id="container">
<%= render "shared/page_header" %>
<%= render "shared/flash_message" %>
<%= yield %>
</div>
</body>
</html>
views/shared/_page_header
<% unless @page_title.blank? %>
<div id="page-header">
<span><%= @page_title %></span>
</div>
<% end %>
Now I have a RegistrationsController to override the functionality whenever I need to but as it inherits to the DeviseController, I don’t think it can get to the Application Helper? I also tried to put this same code in the Registration Helper but that didn’t work either. What should I do?
Maybe you can use;
application_helper.rb
application.html.erb
view