Module: GetsTrolliedControllerHelpers

Defined in:
lib/gets_trollied_controller_helpers.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



2
3
4
# File 'lib/gets_trollied_controller_helpers.rb', line 2

def self.included(klass)
  klass.send :helper_method, :url_for_purchasable_item, :target_action, :target_controller
end

Instance Method Details

#target_action(options = {}) ⇒ Object



11
12
13
# File 'lib/gets_trollied_controller_helpers.rb', line 11

def target_action(options = {})
  options.delete(:action) || 'show'
end

#target_controller(options = {}) ⇒ Object



6
7
8
9
# File 'lib/gets_trollied_controller_helpers.rb', line 6

def target_controller(options = {})
  purchasable_item_params_name = options.delete(:purchasable_item_params_name) || @purchasable_item_params_name
  options.delete(:controller) || purchasable_item_params_name.pluralize || params[:controller]
end

#target_id(options = {}) ⇒ Object



15
16
17
18
# File 'lib/gets_trollied_controller_helpers.rb', line 15

def target_id(options = {})
  purchasable_item = options.delete(:purchasable_item) || @purchasable_item
  options.delete(:id) || purchasable_item
end

#url_for_purchasable_item(options = { }) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/gets_trollied_controller_helpers.rb', line 20

def url_for_purchasable_item(options = { })
  defaults = {
    :controller => target_controller(options),
    :action => target_action(options),
    :id => target_id(options)
  }

  url_for(defaults.merge(options))
end