I have a link_to line of code in an html.erb file:
<%= link_to "no thanks" %>
I want clicking this link to trigger the :reject state method I have set in this ‘treating.rb’ model file:
class Treating < ActiveRecord::Base
attr_accessible :intro, :proposed_date, :proposed_location, :requestee_id, :state
state_machine :state, :initial => :pending do
event :reject do
transition [:pending] => :rejected
end
event :reply do
transition [:pending, :rejected] => :replied
end
event :archive do
transition [:rejected] => :archived
end
end
...
end
What do I put in my link_to line of code to get the ‘treating’ it is referring to to have its status changed from ‘pending’ to ‘rejected’? I’ve tried action => and method => with no success.
You need a controller action to perform this, for example:
I’ve added a member action for the treating resource, and assumed that treatings belong to a user.