Skip to content

Instantly share code, notes, and snippets.

@mati0090
Created February 27, 2012 13:13
Show Gist options
  • Save mati0090/1923694 to your computer and use it in GitHub Desktop.
Save mati0090/1923694 to your computer and use it in GitHub Desktop.
{ send_for_approval: "sent for approval",
deactivate: "deactivated",
reactivate: "reactivated",
}.each do |status, desc|
define_method status do
if @offer.send(status)
redirect_to @offer, :notice => "Offer was #{desc}."
else
render :action => "edit"
end
end
end
@staszek
Copy link

staszek commented Feb 27, 2012

def send_for_approval
  change_state(@offer.send_for_approval, 'sent for approval')
end

def deactivate
  change_state(@offer.deactivate, 'deactivated')
end

def reactivate
  change_state(@offer.reactivate, 'reactivated')
end

private

def change_state(result, snippet)
  if result
    redirect_to @offer, :notice => "Offer was #{snippet}"
  else
    render :action => "edit"
  end
end 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment