RoR:有资源的部分

时间:2009-12-07 22:43:16

标签: ruby-on-rails collections partial-views renderpartial

我有一个问题,尝试使用简短的表示法在轨道上渲染部分红宝石。不知何故,RoR只显示与partial有关的任何内容,但我也没有错误。我的意思是,生成的HTML看起来像部分的调用根本就不存在。我也很困惑,因为我可以在日志中看到,rails渲染了部分2次(没关系,我在dev db中有两个测试条目),但我在浏览器中没有输出。我究竟做错了什么?提前致谢!这是我的代码:

应用程序/视图/教程/ _tutorial.html.erb:

<div class="tutorial">

    <h3><%= link_to tutorial.title, tutorial %></h3>
    <span class="person"><%=h tutorial.tutor %></span>
    <span class="time"><%=h german_time(tutorial.starts_at) %></span>
    <span class="location"><%=h tutorial.location %></span>
    <div class="description"><%=h tutorial.description %></div>
    <% if admin? %>
        <%= link_to 'Edit', edit_tutorial_path(tutorial) %> | 
        <%= link_to 'Delete', tutorial, :confirm => 'Are you sure?', :method => :delete %>
    <% end %>

</div> <!-- end .tutorium -->

应用程序/视图/教程/ index.html.erb:

<h2>Tutorials</h2>

<% render :partial => @tutorials %>

<% if admin? %>
    <%= link_to 'New Tutorial', new_tutorial_path %>
<% end %>

控制台日志:

Processing TutorialsController#index (for 127.0.0.1 at 2009-12-07 23:39:00) [GET]
  Tutorial Load (0.6ms)   SELECT * FROM "tutorials" 
Rendering template within layouts/application
Rendering tutorials/index
Rendered tutorials/_tutorial (7.1ms)
Rendered tutorials/_tutorial (3.7ms)
Completed in 22ms (View: 17, DB: 1) | 200 OK [http://localhost/tutorials]

1 个答案:

答案 0 :(得分:4)

尝试使用等于:

<%= render :partial => @tutorials %>