-
Simple pagination and calling related field
Ahoy.,
I'm just diving into ROR and have a question about pagination. When I use the method
model_name :scaffold
everything works fine, for example I have two tables, ITEMS and CATEGORIES
<% item.category.name %> will give "cars" or something.
When I use the ruby command and create the scaffolding files, then it generates this code:
items_controller.rb
def list
@item_pages, @items = paginate
items,
er_page => 10)
end
list.rhtml
<% @items.each do |item| %>
<tr>
<td><%= item.Category.name %></td>
<td><%= link_to 'Show', :action => 'show', :id => item %></td>
<td><%= link_to 'Edit', :action => 'edit', :id => item %></td>
<td><%= link_to 'Destroy', { :action => 'destroy', :id => item }, :confirm => 'Are you sure?',
ost => true %></td>
</tr>
<% end %>
I get an error on the "item.category.name" . been reading the API and wiki and havn't come up w/ a solution yet. Anyone?
-
Ruby is case-sensitive (unlike PHP). Use
<td><%= item.category.name %></td>
-
I also had a blank entry in the DB, which threw things off. Thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks