2012-08-11 108 views
0

我有设置浏览器和页面本身的标题的方法。在我的设计页面上,我想设置这两个方法,但不知道如何。为Devise页面设置浏览器和页面标题?

我的代码:

佣工/ 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 

的意见/布局/应用

<!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> 

的意见/共享/ _page_header

<% unless @page_title.blank? %> 
    <div id="page-header"> 
    <span><%= @page_title %></span> 
    </div> 
<% end %> 

现在我有一个RegistrationsController来覆盖功能,只要我需要,但因为它继承了DeviseController,我不认为它可以得到应用程序帮助?我也尝试将这个相同的代码放入注册助手中,但那也不起作用。我该怎么办?

+1

'默认DeviseController'延伸'ApplicationController'。 ** [来源](https://github.com/plataformatec/devise/blob/master/lib/devise.rb#L200)** – deefour 2012-08-11 17:58:02

回答

2

也许你可以使用;

application_helper.rb

module ApplicationHelper 
    def title(page_title) 
    content_for(:title) { page_title } 
    end 
end 

application.html.erb

<title><%= yield :title %></title> 

视图

<%= title "Your page title here" %> 
+0

不错,我更喜欢这个。谢谢。 – LearningRoR 2012-09-09 19:34:13