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

Handle js(true) and raise error on invalid argument

This commit is contained in:
kbparauga 2015-08-28 14:13:13 +08:00
parent 481dafb545
commit 2299862500
3 changed files with 29 additions and 6 deletions

View file

@ -67,6 +67,9 @@ module Paloma
#
#
def js path_or_options, params = {}
puts '-----------------------------------------------------------------'
puts "js #{path_or_options.inspect}, #{params.inspect}"
return self.paloma.clear_request if !path_or_options
self.paloma.params.merge! params || {}
@ -80,8 +83,8 @@ module Paloma
#
if path_or_options.is_a? String
route = ::Paloma::Utilities.interpret_route path_or_options
self.paloma.resource = route[:resource] unless route[:resource].blank?
self.paloma.action = route[:action] unless route[:action].blank?
self.paloma.resource = route[:resource] || self.default_resource
self.paloma.action = route[:action] || self.default_action
# :action
elsif path_or_options.is_a? Symbol
@ -91,7 +94,16 @@ 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
raise "Paloma: Invalid argument (#{path_or_options}) for js method"
end
puts "Paloma.request = #{self.paloma.request.inspect}"
puts "Paloma has request? #{self.paloma.has_request?}"
end
@ -101,8 +113,8 @@ module Paloma
# Keeps track of what Rails controller/action is executed.
#
def track_paloma_request
self.paloma.resource ||= ::Paloma::Utilities.get_resource controller_path
self.paloma.action ||= self.action_name
self.paloma.resource ||= self.default_resource
self.paloma.action ||= self.default_action
end
@ -134,6 +146,16 @@ module Paloma
@paloma ||= ::Paloma::Controller.new
end
def default_resource
::Paloma::Utilities.get_resource self.controller_path
end
def default_action
self.action_name
end
end

View file

@ -2,13 +2,14 @@ class MainController < ApplicationController
# Default behavior
def index
js false
js 11231242
render :inline => 'Main#index', :layout => 'application'
end
# Override controller
def show
js false
js 'OtherMain', :x => 1
render :inline => 'Main#show', :layout => 'application'
end