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:
parent
481dafb545
commit
2299862500
3 changed files with 29 additions and 6 deletions
|
@ -67,6 +67,9 @@ module Paloma
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
def js path_or_options, params = {}
|
def js path_or_options, params = {}
|
||||||
|
puts '-----------------------------------------------------------------'
|
||||||
|
puts "js #{path_or_options.inspect}, #{params.inspect}"
|
||||||
|
|
||||||
return self.paloma.clear_request if !path_or_options
|
return self.paloma.clear_request if !path_or_options
|
||||||
|
|
||||||
self.paloma.params.merge! params || {}
|
self.paloma.params.merge! params || {}
|
||||||
|
@ -80,8 +83,8 @@ module Paloma
|
||||||
#
|
#
|
||||||
if path_or_options.is_a? String
|
if path_or_options.is_a? String
|
||||||
route = ::Paloma::Utilities.interpret_route path_or_options
|
route = ::Paloma::Utilities.interpret_route path_or_options
|
||||||
self.paloma.resource = route[:resource] unless route[:resource].blank?
|
self.paloma.resource = route[:resource] || self.default_resource
|
||||||
self.paloma.action = route[:action] unless route[:action].blank?
|
self.paloma.action = route[:action] || self.default_action
|
||||||
|
|
||||||
# :action
|
# :action
|
||||||
elsif path_or_options.is_a? Symbol
|
elsif path_or_options.is_a? Symbol
|
||||||
|
@ -91,7 +94,16 @@ module Paloma
|
||||||
elsif path_or_options.is_a? Hash
|
elsif path_or_options.is_a? Hash
|
||||||
self.paloma.params.merge! path_or_options || {}
|
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
|
end
|
||||||
|
|
||||||
|
puts "Paloma.request = #{self.paloma.request.inspect}"
|
||||||
|
puts "Paloma has request? #{self.paloma.has_request?}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -101,8 +113,8 @@ module Paloma
|
||||||
# Keeps track of what Rails controller/action is executed.
|
# Keeps track of what Rails controller/action is executed.
|
||||||
#
|
#
|
||||||
def track_paloma_request
|
def track_paloma_request
|
||||||
self.paloma.resource ||= ::Paloma::Utilities.get_resource controller_path
|
self.paloma.resource ||= self.default_resource
|
||||||
self.paloma.action ||= self.action_name
|
self.paloma.action ||= self.default_action
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -134,6 +146,16 @@ module Paloma
|
||||||
@paloma ||= ::Paloma::Controller.new
|
@paloma ||= ::Paloma::Controller.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def default_resource
|
||||||
|
::Paloma::Utilities.get_resource self.controller_path
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def default_action
|
||||||
|
self.action_name
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,14 @@ class MainController < ApplicationController
|
||||||
|
|
||||||
# Default behavior
|
# Default behavior
|
||||||
def index
|
def index
|
||||||
|
js false
|
||||||
|
js 11231242
|
||||||
render :inline => 'Main#index', :layout => 'application'
|
render :inline => 'Main#index', :layout => 'application'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# Override controller
|
# Override controller
|
||||||
def show
|
def show
|
||||||
js false
|
|
||||||
js 'OtherMain', :x => 1
|
js 'OtherMain', :x => 1
|
||||||
render :inline => 'Main#show', :layout => 'application'
|
render :inline => 'Main#show', :layout => 'application'
|
||||||
end
|
end
|
||||||
|
|
|
@ -106,4 +106,4 @@ describe Paloma::Controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue