-
-
Save LTe/1923818 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyResponder < ActionController::Responder | |
# Example usage | |
# def controller_method | |
# respond_with @offer | |
# end | |
def to_html | |
if available_methods.keys.include? controller.action | |
if resources.first.send(controller.action) | |
redirect_to resources.first, :notice => "Offer was #{available_methods[controller.action]}." | |
else | |
render :action => "edit" | |
end | |
return # just return, don't execute super | |
end | |
super | |
end | |
# Example usage | |
# def controller_method | |
# respond_with @offer, :change_state => true | |
# end | |
def to_html # another impelemnetation | |
if options[:change_state] | |
if resources.first.send(action.controller) | |
redirect_to resources.first, :notice => "Offer was #{available_methods[controller.action]}." | |
else | |
render :action => "edit" | |
end | |
else | |
super | |
end | |
end | |
protected | |
def available_methods | |
{ | |
send_for_approval: "sent for approval", | |
deactivate: "deactivated" , | |
reactivate: "reactivated" , | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment