代码之家  ›  专栏  ›  技术社区  ›  Patrick Oscity

RoR:带有资源的partials

  •  0
  • Patrick Oscity  · 技术社区  · 16 年前

    我遇到了一个问题,试图在RubyonRails中使用资源的简短符号呈现部分。不知何故,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 -->
    

    <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 回复  |  直到 16 年前
        1
  •  4
  •   MattMcKnight    16 年前

    试着用equals:

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