SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot Dionysis's Avatar
    Join Date
    Jan 2004
    Location
    Socal
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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 = paginateitems,
    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?

  2. #2
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ruby is case-sensitive (unlike PHP). Use

    <td><%= item.category.name %></td>

  3. #3
    SitePoint Zealot Dionysis's Avatar
    Join Date
    Jan 2004
    Location
    Socal
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I also had a blank entry in the DB, which threw things off. Thanks!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •