0

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?

5
  • 3
    All signs point to you having an application.html.erb that you don't think you're using, but you are. Commented Mar 20, 2011 at 16:43
  • It is my application layout file I got the <head> <title><%= @title %></title> </head> Commented Mar 20, 2011 at 16:45
  • I am not using nifty generators Commented Mar 20, 2011 at 16:45
  • Look for Myappname in your app, and where it looks like it is being assigned to something, change it to something else and figure out the source of the problem. Commented Mar 20, 2011 at 16:47
  • I was looking in the wrong view file have now removed my app name Commented Mar 20, 2011 at 16:49

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Good idea I will approve your answer
1

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?

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.