Module: InheritedResources::Helpers::UrlFor

Included in:
ResourcesUrlFor
Defined in:
lib/inherited_resources/helpers/url_for.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
# File 'lib/inherited_resources/helpers/url_for.rb', line 4

def self.included(base)
  base.send(:helper_method, public_instance_methods(false)) if base.respond_to?(:helper_method, true)
end

Instance Method Details

#edit_url(resources, options = {}) ⇒ Object



34
35
36
37
38
# File 'lib/inherited_resources/helpers/url_for.rb', line 34

def edit_url(resources, options = {})
  resources.unshift(:edit) unless resources.first == :edit
  validate_url_helper_arguments!(:edit_url, resources)
  polymorphic_url(resources, options)
end

#index_url(resources, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/inherited_resources/helpers/url_for.rb', line 8

def index_url(resources, options = {})
  if resources.last.respond_to?(:new_record?)
    resources[-1, 1] = resources.last.class
  elsif resources.last.is_a?(Symbol)
    resources[-1, 1] = resources.last.to_s.camelize.singularize.constantize
  end
  validate_url_helper_arguments!(:index_url, resources)
  polymorphic_url(resources, options)
end

#new_url(resources, options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/inherited_resources/helpers/url_for.rb', line 18

def new_url(resources, options = {})
  if resources.last.respond_to?(:new_record?)
    resources[-1, 1] = resources.last.class.name.underscore
  elsif resources.last.is_a?(Class) && resources.last < ActiveRecord::Base
    resources[-1, 1] = resources.last.name.underscore
  end
  resources.unshift(:new) unless resources.first == :new
  validate_url_helper_arguments!(:new_url, resources)
  polymorphic_url(resources, options)
end

#show_url(resources, options = {}) ⇒ Object



29
30
31
32
# File 'lib/inherited_resources/helpers/url_for.rb', line 29

def show_url(resources, options = {})
  validate_url_helper_arguments!(:show_url, resources)
  polymorphic_url(resources, options)
end