diff --git a/lib/paloma/action_controller_extension.rb b/lib/paloma/action_controller_extension.rb index 0a509e3..f325309 100644 --- a/lib/paloma/action_controller_extension.rb +++ b/lib/paloma/action_controller_extension.rb @@ -55,6 +55,20 @@ module Paloma # Can call a different Controller or execute a different action, and # pass parameters. # + # NOTE: + # Calling this more than once in a single action will not clear + # the previous config from the previous call. + # + # Example: + # def new + # js 'MyController#new' + # js :edit + # js :x => 1, :y => 2 + # + # # Paloma will execute JS for + # # MyController#edit and will pass the parameters :x => 1, :y => 2 + # end + # # Usage: # # js 'Controller', {params} @@ -82,8 +96,8 @@ module Paloma # if path_or_options.is_a? String route = ::Paloma::Utilities.interpret_route path_or_options - self.paloma.resource = route[:resource] || self.default_resource - self.paloma.action = route[:action] || self.default_action + self.paloma.resource = route[:resource] if route[:resource].present? + self.paloma.action = route[:action] if route[:action].present? # :action elsif path_or_options.is_a? Symbol @@ -93,13 +107,12 @@ module Paloma elsif path_or_options.is_a? Hash self.paloma.params.merge! path_or_options || {} - elsif path_or_options == true - self.paloma.resource = self.default_resource - self.paloma.action = self.default_action - - else + elsif path_or_options != true raise "Paloma: Invalid argument (#{path_or_options}) for js method" end + + self.paloma.resource ||= self.default_resource + self.paloma.action ||= self.default_action end diff --git a/test_app/app/assets/javascripts/application.js b/test_app/app/assets/javascripts/application.js index 224d3cc..f6a7d06 100644 --- a/test_app/app/assets/javascripts/application.js +++ b/test_app/app/assets/javascripts/application.js @@ -36,12 +36,13 @@ Main.prototype.index = function(){}; Main.prototype.otherAction = function(){}; Main.prototype.prevent = function(){}; Main.prototype.basic_params = function(){}; +Main.prototype.multiple_calls_1 = function(){}; var OtherMain = Paloma.controller('OtherMain'); OtherMain.prototype.show = function(){}; OtherMain.prototype.otherAction = function(){}; - +OtherMain.prototype.multiple_calls_2 = function(){}; var Foos = Paloma.controller('Admin/Foos'); diff --git a/test_app/app/controllers/main_controller.rb b/test_app/app/controllers/main_controller.rb index 529fec7..e25d61b 100644 --- a/test_app/app/controllers/main_controller.rb +++ b/test_app/app/controllers/main_controller.rb @@ -2,8 +2,6 @@ class MainController < ApplicationController # Default behavior def index - js false - js 11231242 render :inline => 'Main#index', :layout => 'application' end @@ -29,6 +27,43 @@ class MainController < ApplicationController end + def multiple_calls_1 + js false + js :x => 70 + render :inline => 'Main#multiple_calls', :layout => 'application' + end + + + def multiple_calls_2 + js false + js 'OtherMain' + render :inline => 'Main#multiple_calls_2', :layout => 'application' + end + + + def multiple_calls_3 + js 'OtherMain' + js :show + render :inline => 'Main#multiple_calls_3', :layout => 'application' + end + + + def multiple_calls_4 + js 'OtherMain#show' + js false + render :inline => 'Main#multiple_calls_4', :layout => 'application' + end + + + def multiple_calls_5 + js false + js true + render :inline => 'Main#multiple_calls_5', :layout => 'application' + end + + + + # Stop paloma from execution def prevent js false diff --git a/test_app/app/views/layouts/application.html.erb b/test_app/app/views/layouts/application.html.erb index e749b21..8d2c635 100644 --- a/test_app/app/views/layouts/application.html.erb +++ b/test_app/app/views/layouts/application.html.erb @@ -17,6 +17,11 @@