This is the way I am approving certain events in my site.
The idea is:
With every new event, an email is send to "admin@example.com". The email contains certain stuff and a link to a method that changes the 'approved' boolean.
Everything works apart from the url generated in the email.
It generates, http://example.com/approve_event . And I get the error 'Could not find an event with id nil'
How should I do to get a url that points to something like http://example.com/approve_event?=23
AdminNotifier
def approve_event(event)
@event = event
mail(:to => "admin@example.com", :subject => "Event pending of approval")
end
email view html
= link_to "Approve", approve_event_url(:id=> @event.id)
EventController
def approved
@event = Event.find(params[:id])
@event.approved = true
@event.save
end
Shall I have in the mailer method something like: @event = Event.find(params[:id] - Sergio Nekora 2012-04-04 18:01
@event
in the view, and for that to work you need to define the @event
variable in the mailer. Take a look at the approve_event
method and check if you're using a valid event object - alf 2012-04-04 18:14
You need to make sure that the @event
variable is defined correctly in the mailer method (approve_event
in this case), to make sure that it will be available in the view.
@event
in the mailer - alf 2012-04-04 17:20