i'm trying to change the status of Dispute object on create and update
i did the attribute inside the method but the status did not changed.
Is better to change the status in the model with callback instead on controller?
def create
Dispute.new
if params[:status] == 'Open'
dispute.status = dispute.statuses[0]
end
if dispute.save
redirect_to dispute_path(@dispute)
flash[:success] = 'Hooray'
else
flash[:error] = 'Error'
redirect_to :back
end
end
on Dispute model
class Dispute < ActiveRecord::Base
STATUSES = %w(open finished).freeze
STATUSES.each do |method|
define_method "#{method}?" do
status == method
end
end
def self.statuses
STATUSES
end
end
Aucun commentaire:
Enregistrer un commentaire