Reputation: 13
I know that by default, views in Rails use the template provided in application.html.erb It's my default template:
<!DOCTYPE html>
<html>
<head>
... any code ...
</head>
<body>
<header> ... any code ... </header>
<%= yield %>
</body>
</html>
I need to transfer the code header> in partial template.
This is my attempt:
I added methode in helpers/application_helper.rb
def layout_header
render 'layouts/header_menu'
end
And called it in application.html.erb
<!DOCTYPE html>
<html>
<head>
... any code ...
</head>
<body>
<%= layout_header %>
<%= yield %>
</body>
</html>
It is my Error: *Missing partial layouts/header_menu with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee, :haml]}. Searched in: * "E:/BDR_SEVERNEFT/app/views"*
I used Rails 3.2 and Ruby 1.9.3
Upvotes: 0
Views: 164
Reputation: 1684
Look at the guide http://guides.rubyonrails.org/layouts_and_rendering.html#using-partials
You can render partials directly in the .erb file using <%= render layout/header_menu %>
and the partial file needs to start with an underscore i.e. "_header_menu.html.erb".
If you want to use your method call approach, call render partial: "layout/header_menu"
and again, make the file name "_header_menu.html.erb".
Upvotes: 1