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 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 <td><%= link_to "EditNew", event/edit %></td> 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 :-) Mike -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 4 November 2010 11:51, Michael Baldock <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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> > 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 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 > > <td><%= link_to "EditNew", event/edit %></td> > > 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 :-) > > Mike > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 04/11/10 12:51, Michael Baldock 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) > > 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 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 > > <td><%= link_to "EditNew", event/edit %></td> > > 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 :-) > > 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) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.