Created
July 3, 2010 16:49
-
-
Save unakatsuo/462692 to your computer and use it in GitHub Desktop.
Rails forward action
This file contains 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 ApplicationController < ActionController::Base | |
helper :all # include all helpers, all the time | |
protect_from_forgery # See ActionController::RequestForgeryProtection for details | |
# Scrub sensitive parameters from your log | |
# filter_parameter_logging :password | |
protected | |
# | |
def forward_action(action_name) | |
raise "Unknown action: #{action_name}" unless self.respond_to?(action_name) | |
self.action_name = request.path_parameters['action'] = action_name.to_s | |
__send__(action_name) | |
end | |
end |
may work with 2.3 only.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This snippet brings the similar feature to JavaServlet's forward() to Rails. It was not enough to just call the action method inside of the requested action. It had to set the destination action name to the current request object as well as ActionController#action_name. Otherwise url_for() keeps to address the requested action path.