开发者

How do I count all objects of stages (one model) in the view of projects (another model) in Rails 3?

This is related to my other question: How do I show all the stages (one model) that belong to a project (another model) in Rails 3?

The only other addition to the code I would add is the updated version of the index view of my projects model:

<h1>Listing projects</h1>

<table>
  <tr>
    <th>Name</th>
    <th>Description</th>
    <th>Number of Stages</th>
  </tr>

<% @projects.each do |project| %>
    <tr>
        <td><%= link_to project.name, project %> | </td>
        <td><%= project.descrip开发者_运维百科tion %> | </td>
        <td><%#= stage.count %></td>

        <% if permitted_to? :edit, @project %>
            <td><%= link_to 'Edit', edit_project_path(project) %></td>
        <% end %>

        <% if permitted_to? :destroy, @project %>
            <td><%= link_to 'Destroy', project, :confirm => 'Are you sure?', :method => :delete %></td>
        <% end %>
    </tr>
<% end %>
</table>

<br />

<% if permitted_to? :create, Project.new %>
    <%= link_to 'New Project', new_project_path %>
<% end %>

Also, can you point me to a link in the Rails guides that can teach me about how to do this?

Thanks.


Try this

<%= project.stages.count %>

The official Rails Guides are pretty good and all new for Rails 3.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜