[英]How can I set seo title tags with Rails Devise on the Sign In and Sign Up pages?
Where in rails + devise can I set a var in the controller like so: 我可以在rails + devise中的哪个位置设置控制器中的var,如下所示:
@content_for_title = 'Sign In'
@content_for_title = 'Sign Up'
Which would then be set in my layout file: 然后将其设置在我的布局文件中:
<title><%= page_title %></title>
Is there a way to take control of: 有没有办法控制:
Devise::SessionsController#new controller to just set that var?
Thanks 谢谢
Other than just adding a 除了添加一个
<title>Mysite | Mysite is so great and here is where you sign in!</title>
In the view, I believe you can partially override the sessions controller to add a @title instance: 在视图中,我相信您可以部分覆盖会话控制器以添加@title实例:
SessionsTitlesController::SessionsController < Devise::SessionsController
def new
@title = "Mysite is so great and here is where you sign in!"
end
end
Then change your routes: 然后更改您的路线:
devise_for :users, :controllers => { :sessions => "sessionstitles" }
Just in case you haven't created Devise views yet, you execute this to generate views: 万一您还没有创建Devise视图,可以执行以下操作来生成视图:
rails generate devise:views
Also, to get the above code to work you'll need to have a title helper in your application_controller along this sort of lines: 同样,要使上述代码正常工作,您需要在application_controller中具有以下几类标题帮助器:
def title
base_title = "My site"
return base_title if @title.nil?
return "#{@title} | #{base_title}
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.