user2527785
user2527785

Reputation: 117

Ruby On Rails Rendering Partial

Hi I am having problems with rendering a partial in a rails view.

I created a partial called _my_header.html.erb in the views/layouts directory.

Then in another file in a different folder in the views called index.html.erb I added:

 <% render 'layouts/my_header' %>

I put this inside a html tag. Anyway I am getting this error:

ActionView::MissingTemplate in User#index

Showing C:/Buzzoo/Buzzoo/app/views/user/index.erb where line #2 raised:
Extracted source (around line #2):

1: <html>
2:  <% render 'layouts/my_header' %>
3: 
4:  <body>

Upvotes: 1

Views: 494

Answers (4)

Amarnath Krishnan
Amarnath Krishnan

Reputation: 1263

ActionView::MissingTemplate in Player#index Showing C:/Buzzoo/Buzzoo/app/views/player/index.mobile.erb where line #2 raised: Missing partial /layouts/mobile_header with {:locale=>[:en], :formats=>[:mobile], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "C:/Buzzoo/Buzzoo/app/views" * "C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/devise-2.1.2/app/views" Extracted source (around line #2): 1: 2: <%= render '/layouts/mobile_header' %> 3: 4:

@user2527785

The above error specifies that there is no partials in the name of mobile_header. Are you sure you have a partial _mobile_header.mobile.erb in your layouts?

Upvotes: 0

Bachan Smruty
Bachan Smruty

Reputation: 5734

Just try the following code

<%= render '/layouts/my_header' %>

Upvotes: 1

Jeroen
Jeroen

Reputation: 13257

You're using the wrong ERB-tags around it, <% %> is for executing code, but <%= %> is for printing code. So this is the correct code:

<%= render 'layouts/my_header' %>

The difference is explained here: What is the difference between <%, <%=, <%# and -%> in ERB in Rails?

And the official docs: http://api.rubyonrails.org/classes/ActionView/Base.html

Upvotes: 2

Peter Tretiakov
Peter Tretiakov

Reputation: 3410

<%= render 'layouts/my_header' %> You need to use <%= %> instead of <% %>, when you want ruby code to show smth in your template.

Upvotes: 1

Related Questions