Module: Paloma::ActionControllerExtension::InstanceMethods

Defined in:
lib/paloma/action_controller_extension.rb

Instance Method Summary collapse

Instance Method Details

#insert_paloma_hookObject

Call in your view to insert Paloma’s html hook.

The html hook contains the javascript code that will execute the tracked Paloma requests.



136
137
138
139
140
141
142
143
144
145
# File 'lib/paloma/action_controller_extension.rb', line 136

def insert_paloma_hook
  return nil if self.paloma.has_no_request?

  hook = view_context.render(
           :partial => 'paloma/hook',
           :locals => {:request => self.paloma.request})

  self.paloma.clear_request
  hook
end

#js(path_or_options, params = {}) ⇒ Object

Specify the behavior of Paloma. Call this manually to override the default Paloma controller/action to be executed.

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}
js 'Controller#action', {params}
js 'Namespace/Controller', {params}
js 'Namespace/Controller#action', {params}
js '#action', {params}
js :action, {params}
js :param_1 => 1, :param_2 => 2
js true
js false


83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/paloma/action_controller_extension.rb', line 83

def js path_or_options, params = {}
  return self.paloma.clear_request if !path_or_options

  self.paloma.params.merge! params || {}

  #
  # 'Controller'
  # 'Controller#action'
  # 'Namespace/Controller'
  # 'Namespace/Controller#action'
  # '#action'
  #
  if path_or_options.is_a? String
    route = ::Paloma::Utilities.interpret_route path_or_options
    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
    self.paloma.action = path_or_options

  # :param_1 => 1, :param_2 => 2
  elsif path_or_options.is_a? Hash
    self.paloma.params.merge! path_or_options || {}

  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

  self.paloma.save_request_history
end

#track_paloma_requestObject

Executed every time a controller action is executed.

Keeps track of what Rails controller/action is executed.



124
125
126
127
# File 'lib/paloma/action_controller_extension.rb', line 124

def track_paloma_request
  self.paloma.resource ||= self.default_resource
  self.paloma.action ||= self.default_action
end