1
0
Fork 0
mirror of https://github.com/kbparagua/paloma synced 2023-03-27 23:21:17 -04:00

Merge pull request #15 from johnknott/master

#13 - Modified to hook module ::ActionController::Flash rather than ::ActionController::Redirect
This commit is contained in:
Karl Bryan Paragua 2013-05-26 20:25:39 -07:00
commit a0c5b34e9d

View file

@ -1,20 +1,20 @@
module Paloma module Paloma
# TODO explain! # TODO explain!
module ::ActionController::Redirecting module ::ActionController::Flash
alias_method :original_redirect_to, :redirect_to alias_method :original_redirect_to, :redirect_to
end end
module ActionControllerExtension module ActionControllerExtension
def redirect_js_hook options = {}, response_status = {} def redirect_js_hook options = {}, response_status_and_flash = {}
add_to_callbacks @__paloma_callback__ add_to_callbacks @__paloma_callback__
original_redirect_to options, response_status original_redirect_to options, response_status_and_flash
end end
alias_method :redirect_to, :redirect_js_hook alias_method :redirect_to, :redirect_js_hook
# #
# js false # js false
# js :new, :params => {} # js :new, :params => {}
@ -24,31 +24,31 @@ module Paloma
def js options = {}, extras = {} def js options = {}, extras = {}
callback = {:controller => controller_path, :action => action_name} callback = {:controller => controller_path, :action => action_name}
params = {} params = {}
if options.is_a? Hash if options.is_a? Hash
params = options[:params] params = options[:params]
callback = options[:controller].present? && options[:action].present? ? callback = options[:controller].present? && options[:action].present? ?
{:controller => options[:controller], :action => options[:action]} : {:controller => options[:controller], :action => options[:action]} :
callback callback
elsif options.is_a? Symbol elsif options.is_a? Symbol
params = extras[:params] params = extras[:params]
callback[:action] = options callback[:action] = options
elsif options.is_a? FalseClass elsif options.is_a? FalseClass
callback = nil callback = nil
end end
params ||= {} params ||= {}
# Include request details # Include request details
params[:controller_path] = controller_path params[:controller_path] = controller_path
params[:action] = action_name params[:action] = action_name
@__paloma_callback__ = callback.present? ? callback.merge({:params => params}) : nil @__paloma_callback__ = callback.present? ? callback.merge({:params => params}) : nil
end end
end end
::ActionController::Base.send :include, ActionControllerExtension ::ActionController::Base.send :include, ActionControllerExtension
end end