Help please solve the problem. ROR-site consists of layouts and templates. On most sites, the page title is displayed in a template. Therefore, there are no problems with displaying the page title.

But on my site you want to display the title of the page somewhere in the header area. I did the following: Created a helper:

module ApplicationHelper def get_page_title full_path = request.fullpath puts case full_path when '/pages/contact' page_title = 'Контактная информация' when '/blog_articles' page_title = 'Блог' when '/pages/portfolio' page_title = 'Портфолио' when '/pages/about' page_title = 'О нас' when '/' page_title = 'Главная' else page_title = 'Страница не найдена' end return page_title end end 

and embedded this helper in the template:

 <div id="content_top"> <div id="page_title"><%= get_page_title %></div> </div> 

The way is working, but not beautiful because if something changes in the routing, then the helper will also have to rule.

Please tell me how this problem is solved.

    1 answer 1

    If I understood correctly, then the problem is that the text should be output in that part of the pages for which the layout is responsible, and the text itself is known only "inside the template".

    To do this, there is a yield .

    In layout:

     <div id="content_top"> <div id="page_title"><%= yield :title %></div> </div> 

    In the presentation:

     <% content_for :title do %>  Мой замечательный заголовок <% end %>