simple question about editing data in model

I'm guessing this is easy, but I still cant do it!!

In my app I have a number of different models describing events, london_events, new_york_events, scotland_events etc etc, each of these has columns to describe the events (Venue, time, place, band etc etc)

To display the events, I have a different page for each location (London / New York / Scotland), and on that page I make a table with info columns, Event name, Band Name etc etc, and for each row (event) I want to have the standard buttons, 'show', 'edit', 'delete'.

To keep code DRY I've made a generic view "/shared/_index_events_table" which then gets passed all the events for the location

the generic table code looks like this: (events_group = @london_events / @scotland_events etc etc...)

<table>   <tr>     <th>Event Name</th>     <th>Band Name</th>     <th>S3 filename</th>   </tr>

<% events_group.each do |event| %>   <tr>     <td><%=h event.eventName %></td>     <td><%=h event.bandName %></td>     <td><%=h event.s3filename %></td>   <td><%= link_to 'Show', event %></td>

        #This works fine, but is specific to the location   <td><%= link_to "EditOld", edit_london_events_path(event) %></td>

        #How do I get to the 'edit' path for any event???   <td><%= link_to "EditNew", event/edit %></td>

    <td><%= link_to "Delete", event, :method => :delete, :confirm => 'Are you sure?',                    :title => "Delete Event" %></td>   </tr> <% end %> </table>

I'm guessing this is easy, but I still cant do it!!

In my app I have a number of different models describing events, london_events, new_york_events, scotland_events etc etc, each of these has columns to describe the events (Venue, time, place, band etc etc)

Are you making life difficult for yourself by having multiple tables? Why not have one table with with either a field for location or a separate table for the locations with event belongs_to location? Then your problem may go away.

Colin

Why haven't you got only one model, with a location-column and an index on :location? So you only need one show-action with a :path_prefix => "/:location" in route resources. I think, this would be much more DRY.

But ok, your question was another. Perhaps your events are seeming more alike than they are.

I think, you could use: polymorphic_path(event, :action => :edit)

Thanks for your help!

@Colin - One big table isn't really appropriate on the site, as there's more info than just the table on each location page.

@Colin & @smbepiec

"separate table for the locations with event belongs_to location?"

"Why haven't you got only one model, with a location-column and an index on :location?"

I'm not quite sure of the differences between approaches here, need more practice, but if I understand you correctly, you mean to have one model (events), but with a column for whichever location it belongs to. This might well be an idea for a revised version of the site. There are some complications with this though, not all events are exactly the same, the London event has a tube-station stop for example. Also, the site links to an iPhone app using objective resource. Objective resource cleverly links between model names and columns on the rails side, to classes and properties on the iPhone (Objective-C) side. with the single line [LondAllEvent findAllRemote].

This is another reason why I wanted to keep the models separate, so that when someone's using the app, they only download the data specific to the location, not all data for all locations. I'm sure there's a way in objective resource to only download data according to certain column values in rails, but again inexperience lets me down...

So for now, I'm gonna stick with the 'many similar models' (not so very DRY) structure, but thanks for the advice, maybe next time!

@smbepiec

"I think, you could use: polymorphic_path(event, :action => :edit)"

Brilliant, that's it working now cheers :-))

Thanks both.

MIke