Module: GetsTrolliedControllerHelpers
- Defined in:
- lib/gets_trollied_controller_helpers.rb
Class Method Summary collapse
Instance Method Summary collapse
- #target_action(options = {}) ⇒ Object
- #target_controller(options = {}) ⇒ Object
- #target_id(options = {}) ⇒ Object
- #url_for_purchasable_item(options = { }) ⇒ Object
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( = {}) .delete(:action) || 'show' end |
#target_controller(options = {}) ⇒ Object
6 7 8 9 |
# File 'lib/gets_trollied_controller_helpers.rb', line 6 def target_controller( = {}) purchasable_item_params_name = .delete(:purchasable_item_params_name) || @purchasable_item_params_name .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( = {}) purchasable_item = .delete(:purchasable_item) || @purchasable_item .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( = { }) defaults = { :controller => target_controller(), :action => target_action(), :id => target_id() } url_for(defaults.merge()) end |