Sha256: b145aa3de43033934cdf4b55bffa91952b9dd88434bd5e3e4548de342aeb3305

Contents?: true

Size: 897 Bytes

Versions: 5

Compression:

Stored size: 897 Bytes

Contents

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

  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

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

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

  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
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
trollied-0.1.4 lib/gets_trollied_controller_helpers.rb
trollied-0.1.3 lib/gets_trollied_controller_helpers.rb
trollied-0.1.2 lib/gets_trollied_controller_helpers.rb
trollied-0.1.1 lib/gets_trollied_controller_helpers.rb
trollied-0.1.0 lib/gets_trollied_controller_helpers.rb