开发者

Rails 3 how to remove the app name in page title?

In my layout file I have

<head>
  <title><%=开发者_运维问答 @title %></title>
</head>

And in my show file:

<% @title = Item.name %>

The problem is that in the page title there is added | Myappname instead of just the Item name

How do I remove the app name in page title?


You should define @title in the controller action instead of view. Instead of defining it in show file, you should define it in show method.

def show
  @title = Item.name
  ...
end

This is because, the show file is evaluated after rendering the layout application.html.erb, so defining @title afterwards in the show view file will not affect the @tilte in the application.html layout.


Layout is evaluated before your show file. That is why @title = Item.name doesn't affect to your html page title.

I think you should check this: Rails: How to change the title of a page?


check if there's a filter in your ApplicationController.rb pushing your app name in @title

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜