【问题标题】:RoR: partials with resourcesRoR:具有资源的部分
【发布时间】:2009-12-07 22:43:16
【问题描述】:

我有一个问题,试图用资源的简写法在 ruby​​ on rails 中渲染部分。不知何故,RoR 显示的内容与部分无关,但我也没有收到任何错误。我的意思是,生成的 HTML 看起来根本不存在对部分的调用。我也很困惑,因为我可以在日志中看到,rails 渲染了部分 2 次(没关系,我在 dev db 中有两个测试条目),但我在浏览器中没有输出。我究竟做错了什么?提前致谢!这是我的代码:

app/views/tutorials/_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 -->

app/views/tutorials/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]

【问题讨论】:

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


    【解决方案1】:

    用等号试试:

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

    【讨论】:

    • 如果你不指定
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-06
    • 1970-01-01
    • 2014-06-14
    • 1970-01-01
    • 2012-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多