【问题标题】:rendering a different template in rails在 Rails 中渲染不同的模板
【发布时间】:2012-09-15 14:03:26
【问题描述】:

我有一个观点

<%= render :partial => @list.items%>

显示这个命令叫做_item.html.erb。对吧?

<div class="well">
  <%= image_tag item.photo.url(:small) %><br>
  <b>Title</b> <%= item.title %><br />
  <b>Description</b> <%= item.description %>
</div>

这很好用。 现在我有另一个名为_ilist.html.erb 的模板,我需要其中的一些数据。 我尝试通过添加模板选项来呈现它。但不会使用其他模板。第一个模板将随时调用。

<%= render :partial => @list.items, :template => 'items/ilist' %>

有没有调用其他_ilist-template的选项?

感谢您的帮助

【问题讨论】:

    标签: ruby-on-rails templates rendering ruby-on-rails-3.2


    【解决方案1】:

    我相信你需要:

    <%= render :partial => 'items/ilist', :collection => @list.items, :as => :item %>
    

    【讨论】:

    • 谢谢。但是现在我在第二行出现错误(对于测试,我复制了 item.html.erb)&lt;div class="well-form"&gt; &lt;%= image_tag item.photo.url%&gt;&lt;br&gt; &lt;b&gt;Wunsch:&lt;/b&gt; &lt;%= item.title %&gt;&lt;br /&gt; &lt;b&gt;Beschreibung:&lt;/b&gt; &lt;%= item.description %&gt; &lt;/div&gt; &lt;p&gt;Reservieren&lt;/p&gt;undefined local variable or method item' for #:0x007fcb645f8390>`
    • 在你的渲染语句中也传入 ":as => :item"
    • 非常感谢它运行良好。现在我知道这句话是什么意思了
    猜你喜欢
    • 2011-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-24
    • 1970-01-01
    • 2021-11-07
    • 2014-11-22
    • 2012-12-31
    相关资源
    最近更新 更多