The interaction of the site is based on the input of user. For example, if the user selected "VISA" as payment method, he will be redirected to another controller/actions asking for credit card number. If the user selected "Paypal", then he/she will be redirected to an external website.
Instead of putting all logic in the action itself, I'm thinking of abstracting it in an object, for the sake of extensibility. Example.
class Payment < ActiveRecord::Base; end
class VisaPayment < Payment
def process
...
end
end
class PaypalPayment < Payment
def process(controller)
...
controller.redirect_to "http://paypal.com"
end
end
class OrdersController < ApplicationController
def accept
params[:select].constantize.new.process(self)
end
end
This doesn't work because methods like "redirect_to" are protected. Is there any idiom or common pattern for this kind of delegation?
p.s. the code above is truly imagination, not excerpt of any actual coding