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…)

<% events_group.each do |event| %>

    #This works fine, but is specific to the location
    #How do I get to the 'edit' path for any event???
<td><%= link_to "Delete", event, :method => :delete, :confirm =>

‘Are you sure?’,
:title => “Delete Event” %>

<% end %>
Event Name Band Name S3 filename
<%=h event.eventName %> <%=h event.bandName %> <%=h event.s3filename %> <%= link_to 'Show', event %> <%= link_to "EditOld", edit_london_events_path(event) %> <%= link_to "EditNew", event/edit %>

I can get to the edit path for the event using

edit_london_events_path(event)

but this is specific to London, and so I’d need to make a new table for
each location - not DRY!!!

what I’d like is to get the edit path from the event, something like

<%= link_to "EditNew", event/edit %>

but this returns "undefined local variable or method `edit’ "

I’ve tried a number of different guesses as to how to do this, but none
of them have worked!

Can anyone tell me how to do this please.

All help appreciated :slight_smile:

Mike

On 4 November 2010 11:51, Michael B. [email protected] wrote:

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

On 04/11/10 12:51, Michael B. wrote:

 <th>S3 filename</th>
     #This works fine, but is specific to the location
but this is specific to London, and so I'd need to make a new table for

Can anyone tell me how to do this please.

All help appreciated :slight_smile:

Mike

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