Rails3 嵌套布局和局部传递参数
嘿, 我正在处理一个具有嵌套布局的页面。首先,我有“主菜单”的应用程序布局,现在我想仅在此页面上添加第二个菜单。 来完成此工作
<% render :partial => "mypartial", :layout => 'navigation' %>
我通过将第二个导航添加到表单并呈现部分内容
。此时我尝试区分两个不同的部分。所以我的文件看起来像这样
<% if :passed_text == "page1" %>
<%= render :partial => "mypartial1", :layout => 'navigation' %>
<% else %>
<%= render :partial => "mypartial2", :layout => 'navigation' %>
<% end %>
我的导航如下:
<%= link_to "Mypartial1", partial_path, :passed_text => :page1 %>
<%= link_to "Mypartial2", partial_path, :passed_text => :page2 %>
<%= yield %>
但它忽略了我的参数。我想我错过了一些基本的东西,但这一切对我来说都是新的。 感谢您的帮助
Hey,
I'm working on a page having a nested layout. first I have the applicationlayout with my "mainmenu" now I want to add a second menu only on this page. I got this working via
<% render :partial => "mypartial", :layout => 'navigation' %>
this adds my second navigation to the form and renders a partial.
At this point I try to distinguish between two different partials. so my file looks like this
<% if :passed_text == "page1" %>
<%= render :partial => "mypartial1", :layout => 'navigation' %>
<% else %>
<%= render :partial => "mypartial2", :layout => 'navigation' %>
<% end %>
my navigation is as follows:
<%= link_to "Mypartial1", partial_path, :passed_text => :page1 %>
<%= link_to "Mypartial2", partial_path, :passed_text => :page2 %>
<%= yield %>
but it ignores my parameters. I guess I'm missing something basic, but all this is new to me.
thanks for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我找到了答案:
首先我必须检查:
而不是 :passed_text
其次传递参数必须放在括号中,
这可以正常工作
okay I found an answer:
first I have to check for:
instead of :passed_text
secondly passing the parameters has to be in brackets
this works fine