small medium large xlarge

Generic-user-small
20 Nov 2007, 22:38
Cris Paltenghe (4 posts)

I am a Rails newbie and trying to apply what I have been learning in the book. I recently created an object that contains a foreign key into a look up table. The goal was to get a drop down list and pick the value from the look up table. I ended up creating a scaffold and editing the views to implement the look up in edit, list, new, and show. The amount of code wasn’t bad at all, and it seemed to work. Once, however, I had more rows than fit on a page, LIST didn’t seem to function correctly. Even though it would accept “next page”, and show an incremented page number in the console log, the data didn’t change on the form, and always showed the first page of data. In the example below, the Operating_Systems table looks up Service_Pack name from another table via a hidden ID.

Listing Operating Systems

<% for column in OperatingSystem.content_columns %> <%= column.human_name %> <% end %> Service Pack <% for operating_system in @operating_systems %> <% for column in OperatingSystem.content_columns %> <%=h operating_system.send(column.name) %> <% end %> <%=h (ServicePack.find(operating_system.service_pack_id)).title %> <%= link_to 'Show', :action => 'show', :id => operating_system %> <%= link_to 'Edit', :action => 'edit', :id => operating_system %> <%= link_to 'Destroy', { :action => 'destroy', :id => operating_system }, :confirm => 'Are you sure?', :method => :post %> <% end %>

<%= link_to ‘Previous page’, { :page => @operating_system_pages.current.previous } if @operating_system_pages.current.previous %> <%= link_to ‘Next page’, { :page => @operating_system_pages.current.next } if @operating_system_pages.current.next %>


<%= link_to ‘New operating_system’, :action => ‘new’ %>

The Result always looks like the following….

Listing Operating Systems Title Non compliant SP Windows 2000 Datacenter Server false SP0 Show Edit Destroy Windows 2000 Professional false SP0 Show Edit Destroy Windows 2000 Server false SP0 Show Edit Destroy Windows 2000 Advanced Server false SP1 Show Edit Destroy Windows 2000 Datacenter Server false SP1 Show Edit Destroy Windows 2000 Professional false SP1 Show Edit Destroy Windows 2000 Server false SP1 Show Edit Destroy Windows 2000 Advanced Server false SP2 Show Edit Destroy Windows 2000 Datacenter Server false SP2 Show Edit Destroy Windows 2000 Professional false SP2 Show Edit Destroy Previous page Next page New operating_system

There are 189 rows in the actual table, all with unique ID’s

I’m not even sure where to go looking on how to resolve this. Additionally, I would like to increase the number of items shown a given page.

Comments and/or suggestions?

Generic-user-small
21 Nov 2007, 17:32
Cris Paltenghe (4 posts)

I just realized that this has nothing to do with lookup tables per se, there appears to be a problem with LIST. I just dumped the contents of a table that stores Service Pack Descriptions…

ID Title 1 Any 2 SP0 3 SP1 4 SP2 5 SP3 6 SP4 7 SP5 8 SP6 9 SP7 10 SP8 11 SP9 12 SP10

Notice there are 12 entries. From a rails generated scaffold with no modification, I get the following for the 1st page of LIST… Listing service_packs Title Any Show Edit Destroy SP0 Show Edit Destroy SP1 Show Edit Destroy SP2 Show Edit Destroy SP3 Show Edit Destroy SP4 Show Edit Destroy SP5 Show Edit Destroy SP6 Show Edit Destroy SP7 Show Edit Destroy SP8 Show Edit Destroy Next page New service_pack

So good so far, but them pressing next page, I get…

Listing service_packs Title Any Show Edit Destroy SP0 Show Edit Destroy Previous page New service_pack

Notice it just shows the fist two entries, instead of 9 - 12 like it should…

Does anyone know what is happening here and how I can correct it?

You must be logged in to comment