Module Resourceful::Default::URLs
In: lib/resourceful/default/urls.rb

This file contains various methods to make URL helpers less painful. They provide methods analogous to the standard foo_url and foo_path helpers. However, they use make_resourceful’s knowledge of the structure of the controller to allow you to avoid figuring out which method to call and which parent objects it should be passed.

Methods

Public Instance methods

This returns the path for the edit action for the given object, by default current_object. For example, in HatsController where Person has_many :hats, the following are equivalent:

  edit_object_path                    #=> "/people/42/hats/12/edit"
  edit_person_hat_path(@person, @hat) #=> "/people/42/hats/12/edit"

[Source]

    # File lib/resourceful/default/urls.rb, line 28
28:       def edit_object_path(object = current_object); edit_object_route(object, 'path'); end

Same as edit_object_path, but with the protocol and hostname.

[Source]

    # File lib/resourceful/default/urls.rb, line 30
30:       def edit_object_url (object = current_object); edit_object_route(object, 'url');  end

This returns the path for the new action for the current controller. For example, in HatsController where Person has_many :hats, the following are equivalent:

  new_object_path              #=> "/people/42/hats/new"
  new_person_hat_path(@person) #=> "/people/42/hats/new"

[Source]

    # File lib/resourceful/default/urls.rb, line 50
50:       def new_object_path; new_object_route('path'); end

Same as new_object_path, but with the protocol and hostname.

[Source]

    # File lib/resourceful/default/urls.rb, line 52
52:       def new_object_url ; new_object_route('url');  end

This returns the path for the given object, by default current_object. For example, in HatsController where Person has_many :hats, the following are equivalent:

  object_path                    #=> "/people/42/hats/12"
  person_hat_path(@person, @hat) #=> "/people/42/hats/12"

[Source]

    # File lib/resourceful/default/urls.rb, line 16
16:       def object_path(object = current_object); object_route(object, 'path'); end

Same as object_path, but with the protocol and hostname.

[Source]

    # File lib/resourceful/default/urls.rb, line 18
18:       def object_url (object = current_object); object_route(object, 'url');  end

This returns the path for the collection of the current controller. For example, in HatsController where Person has_many :hats, the following are equivalent:

  objects_path              #=> "/people/42/hats"
  person_hats_path(@person) #=> "/people/42/hats"

[Source]

    # File lib/resourceful/default/urls.rb, line 39
39:       def objects_path; objects_route('path'); end

Same as objects_path, but with the protocol and hostname.

[Source]

    # File lib/resourceful/default/urls.rb, line 41
41:       def objects_url ; objects_route('url');  end

This prefix is added to the Rails URL helper names before they’re called. By default, it’s the underscored list of namespaces of the current controller, or the underscored list of parents if there are no namespaces defined. However, it can be overridden if another prefix is needed. Note that if this is overridden, the new method should return a string ending in an underscore.

For example, in Admin::Content::PagesController:

  url_helper_prefix #=> "admin_content_"

Then object_path is the same as admin_content_page_path(current_object).

[Source]

    # File lib/resourceful/default/urls.rb, line 67
67:       def url_helper_prefix
68:         if defined?(namespace_prefix)
69:           STDERR.puts "DEPRECATION WARNING: \nThe make_resourceful #namespace_prefix accessor\nis deprecated and will be removed in 0.3.0.\nOverride #url_method_prefix instead.\n".gsub("\n", ' ')
70:           return namespace_prefix
71:         end
72:         
73:         prefixes = namespaces.empty? ? parents : namespaces
74:         prefixes.empty? ? '' : "#{prefixes.join('_')}_"
75:       end

[Validate]