Hi all,
I have a model Events, with the attributes relating to events, event name / band / date etc, and venue.
I also have a model called venue, and all the different saved venues are presented as a dropdown list when creating a new event.
Attributes associated with the saved venue such as latitude and longitude are then copied over to the event being saved. This works fine.
However when I go back to the saved event and try to update it, if I choose a new venue from the list and press update, the latitude / longitude values aren't getting copied over. I've tried many possible solutions, sometimes with temporary success (on first try), but none of them work continuously, here's what I've tried
<code> EventController
def update
@event = Event.find(params[:id]) @venue = (Venue.where(:venueName => @event.venue))[0]
if @venue @event.city_location = @venue.city_location @event.longitude = @venue.longitude @event.latitude = @venue.latitude end
if @event.update_attributes(params[:suggested_event])
flash[:success] = "SuggestedEvent updated." redirect_to @event
</code>
Values didn't change.
I tried this in the console and got the error
NameError: undefined local variable or method `params' for #<Object:0x100177298> from (irb):7
and in the console removing the word 'params' seemed to do the trick, so updated the code to <code> ... if @event.update_attributes(:suggested_event) .... </code>
This worked once, then never again!!!
I've also tried
<code>
@event = Event.find(params[:id]) @venue = (Venue.where(:venueName => @event.venue))[0]
if @venue @event.update_attributes(:city_location => @venue.city_location) @event.update_attributes(:longitude => @venue.longitude) @event.update_attributes(:latitude => @venue.latitude) end
if @event.update_attributes(params[:suggested_event])
flash[:success] = "SuggestedEvent updated." redirect_to @event </code>
but again the values didn't change.
Could anyone please tell me
a - how to update values of active record properly in this case? b - why console doesn't recognise 'params' and c - why on earth might the 2nd try have worked once, and then never again! (unless it was a mirage?!)
Any help massively appreciated
Mike
ps. I deliberately wanted the values to be copied over, so that afterwards I could 'tweak' each event individually, for example by having a very slightly different latitude on multiple events in the same venue means on my google map view of how to get to them, I get multiple pins!!