[英]Ruby On Rails Rendering Partial
Hi I am having problems with rendering a partial in a rails view. 嗨我在rails视图中渲染部分时遇到问题。
I created a partial called _my_header.html.erb
in the views/layouts directory. 我在views / layouts目录中创建了一个名为
_my_header.html.erb
的部分。
Then in another file in a different folder in the views called index.html.erb
I added: 然后在名为
index.html.erb
的视图中的另一个文件夹中的另一个文件中添加了:
<% render 'layouts/my_header' %>
I put this inside a html tag. 我把它放在一个html标签里面。 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>
You're using the wrong ERB-tags around it, <% %>
is for executing code, but <%= %>
is for printing code. 你在它周围使用了错误的ERB标签,
<% %>
用于执行代码,但<%= %>
用于打印代码。 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? 这里解释了不同之处 : Rails中ERB中的<%,<%=,<%#和 - %>有什么区别?
And the official docs: http://api.rubyonrails.org/classes/ActionView/Base.html 官方文档: http : //api.rubyonrails.org/classes/ActionView/Base.html
<%= render 'layouts/my_header' %>
当您希望ruby代码在模板中显示smth时,需要使用<%= %>
而不是<% %>
。
只需尝试以下代码即可
<%= render '/layouts/my_header' %>
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]}.
Player#index中的ActionView :: MissingTemplate显示C:/Buzzoo/Buzzoo/app/views/player/index.mobile.erb第2行引发:缺少部分/布局/ mobile_header {: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:
搜索:*“C:/ Buzzoo / Buzzoo / app / views”*“C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/devise-2.1.2/app/views”已提取来源(第2行):1:2:<%=渲染'/ layouts / mobile_header'%> 3:4:
@user2527785 @ user2527785
The above error specifies that there is no partials in the name of mobile_header. 上述错误指定mobile_header名称中没有部分内容。 Are you sure you have a partial _mobile_header.mobile.erb in your layouts?
您确定布局中有部分_mobile_header.mobile.erb吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.