我正在实现一个库,并且有一个类别表。
类别表如下:-
id serial NOT NULL,
name character varying(255),
parent_cat_id integer DEFAULT 0,
deleted integer NOT NULL DEFAULT 0,
CONSTRAINT categories_pkey PRIMARY KEY (id)
现在我面临的问题是我想显示类别的名称而不是引用的类别的 id。
我的 index.html.erb 文件如下:-
<table class="table table-striped table-bordered">
<tr>
<th>Id</th>
<th>Name</th>
<th>Parent Category Id</th>
<th>Edit</th>
<th>Delete</th>
</tr>
<% @categories.each do |c| %>
<tr>
<td><%= c.id %> </td>
<td><%= c.name %> </td>
<td><%= c.parent_cat_id %> </td>
<td><%= link_to 'Edit', {:action => 'edit', :id => c.id} %> </td>
<td><%= link_to 'Delete', {:action => 'delete', :id => c.id},
:data => { :confirm => "Are you sure you want to delete this value?" } %></td>
</tr>
</tr>
<% end %>
</table>
<br />
有什么办法可以实现这一点。