0
@@ -2,48 +2,68 @@ module ActionController
0
class Resource #:nodoc:
0
attr_reader :collection_methods, :member_methods, :new_methods
0
- attr_reader :path_prefix, :name_prefix
0
+ attr_reader :path_prefix, :new_name_prefix
0
attr_reader :plural, :singular
0
def initialize(entities, options)
0
@singular = options[:singular] || plural.to_s.singularize
0
@controller ||= (options[:controller] || plural).to_s
0
@path ||= "#{path_prefix}/#{plural}"
0
@new_path ||= "#{path}/new"
0
@member_path ||= "#{path}/:id"
0
def nesting_path_prefix
0
@nesting_path_prefix ||= "#{path}/:#{singular}_id"
0
+ def deprecate_name_prefix?
0
+ @name_prefix.blank? && !@new_name_prefix.blank?
0
+ deprecate_name_prefix? ? @new_name_prefix : @name_prefix
0
+ def nesting_name_prefix
0
+ "#{new_name_prefix}#{singular}_"
0
+ @action_separator ||= Base.resource_action_separator
0
@collection_methods = arrange_actions_by_methods(options.delete(:collection))
0
@member_methods = arrange_actions_by_methods(options.delete(:member))
0
@new_methods = arrange_actions_by_methods(options.delete(:new))
0
def add_default_actions
0
add_default_action(member_methods, :get, :edit)
0
add_default_action(new_methods, :get, :new)
0
@@ -52,6 +72,7 @@ module ActionController
0
@path_prefix = options.delete(:path_prefix)
0
@name_prefix = options.delete(:name_prefix)
0
+ @new_name_prefix = options.delete(:new_name_prefix)
0
def arrange_actions_by_methods(actions)
0
@@ -60,7 +81,7 @@ module ActionController
0
def add_default_action(collection, method, action)
0
(collection[method] ||= []).unshift(action)
0
@@ -178,11 +199,11 @@ module ActionController
0
# The comment resources work the same, but must now include a value for :article_id.
0
- # comments_url(@article)
0
- # comment_url(@article, @comment)
0
+ # article_comments_url(@article)
0
+ # article_comment_url(@article, @comment)
0
- # comments_url(:article_id => @article)
0
- # comment_url(:article_id => @article, :id => @comment)
0
+ # article_comments_url(:article_id => @article)
0
+ # article_comment_url(:article_id => @article, :id => @comment)
0
# * <tt>:name_prefix</tt> -- define a prefix for all generated routes, usually ending in an underscore.
0
# Use this if you have named routes that may clash.
0
@@ -192,7 +213,7 @@ module ActionController
0
# * <tt>:collection</tt> -- add named routes for other actions that operate on the collection.
0
# Takes a hash of <tt>#{action} => #{method}</tt>, where method is <tt>:get</tt>/<tt>:post</tt>/<tt>:put</tt>/<tt>:delete</tt>
0
- # or <tt>:any</tt> if the method does not matter. These routes map to a URL like /messages;rss, with a route of rss_messages_url.
0
+ # or <tt>:any</tt> if the method does not matter. These routes map to a URL like /messages/rss, with a route of rss_messages_url.
0
# * <tt>:member</tt> -- same as :collection, but for actions that operate on a specific member.
0
# * <tt>:new</tt> -- same as :collection, but for actions that operate on the new resource action.
0
@@ -204,19 +225,19 @@ module ActionController
0
# # --> GET /thread/7/messages/1
0
# map.resources :messages, :collection => { :rss => :get }
0
- # # --> GET /messages;rss (maps to the #rss action)
0
+ # # --> GET /messages/rss (maps to the #rss action)
0
# # also adds a named route called "rss_messages"
0
# map.resources :messages, :member => { :mark => :post }
0
- # # --> POST /messages/1;mark (maps to the #mark action)
0
+ # # --> POST /messages/1/mark (maps to the #mark action)
0
# # also adds a named route called "mark_message"
0
# map.resources :messages, :new => { :preview => :post }
0
- # # --> POST /messages/new;preview (maps to the #preview action)
0
+ # # --> POST /messages/new/preview (maps to the #preview action)
0
# # also adds a named route called "preview_new_message"
0
# map.resources :messages, :new => { :new => :any, :preview => :post }
0
- # # --> POST /messages/new;preview (maps to the #preview action)
0
+ # # --> POST /messages/new/preview (maps to the #preview action)
0
# # also adds a named route called "preview_new_message"
0
# # --> /messages/new can be invoked via any request method
0
@@ -235,9 +256,10 @@ module ActionController
0
# See map.resources for general conventions. These are the main differences:
0
- # - a singular name is given to map.resource. The default controller name is taken from the singular name.
0
- # - To specify a custom plural name, use the :plural option. There is no :singular option
0
- # - No default index, new, or create routes are created for the singleton resource controller.
0
+ # - A singular name is given to map.resource. The default controller name is taken from the singular name.
0
+ # - There is no <tt>:collection</tt> option as there is only the singleton resource.
0
+ # - There is no <tt>:singular</tt> option as the singular name is passed to map.resource.
0
+ # - No default index route is created for the singleton resource controller.
0
# - When nesting singleton resources, only the singular name is used as the path prefix (example: 'account/messages/1')
0
@@ -300,7 +322,7 @@ module ActionController
0
map_member_actions(map, resource)
0
- with_options(:path_prefix => resource.nesting_path_prefix, &block)
0
+ with_options(:path_prefix => resource.nesting_path_prefix, :new_name_prefix => resource.nesting_name_prefix, &block)
0
@@ -315,7 +337,7 @@ module ActionController
0
map_member_actions(map, resource)
0
- with_options(:path_prefix => resource.nesting_path_prefix, &block)
0
+ with_options(:path_prefix => resource.nesting_path_prefix, :new_name_prefix => resource.nesting_name_prefix, &block)
0
@@ -324,8 +346,21 @@ module ActionController
0
resource.collection_methods.each do |method, actions|
0
actions.each do |action|
0
action_options = action_options_for(action, resource, method)
0
- map.named_route("#{resource.name_prefix}#{action}_#{resource.plural}", "#{resource.path};#{action}", action_options)
0
- map.named_route("formatted_#{resource.name_prefix}#{action}_#{resource.plural}", "#{resource.path}.:format;#{action}", action_options)
0
+ unless resource.old_name_prefix.blank?
0
+ map.deprecated_named_route("#{action}_#{resource.name_prefix}#{resource.plural}", "#{resource.old_name_prefix}#{action}_#{resource.plural}")
0
+ map.deprecated_named_route("formatted_#{action}_#{resource.name_prefix}#{resource.plural}", "formatted_#{resource.old_name_prefix}#{action}_#{resource.plural}")
0
+ if resource.deprecate_name_prefix?
0
+ map.deprecated_named_route("#{action}_#{resource.name_prefix}#{resource.plural}", "#{action}_#{resource.plural}")
0
+ map.deprecated_named_route("formatted_#{action}_#{resource.name_prefix}#{resource.plural}", "formatted_#{action}_#{resource.plural}")
0
+ map.named_route("#{action}_#{resource.name_prefix}#{resource.plural}", "#{resource.path}#{resource.action_separator}#{action}", action_options)
0
+ map.connect("#{resource.path};#{action}", action_options)
0
+ map.connect("#{resource.path}.:format;#{action}", action_options)
0
+ map.named_route("formatted_#{action}_#{resource.name_prefix}#{resource.plural}", "#{resource.path}#{resource.action_separator}#{action}.:format", action_options)
0
@@ -335,6 +370,11 @@ module ActionController
0
map.named_route("#{resource.name_prefix}#{resource.plural}", resource.path, index_action_options)
0
map.named_route("formatted_#{resource.name_prefix}#{resource.plural}", "#{resource.path}.:format", index_action_options)
0
+ if resource.deprecate_name_prefix?
0
+ map.deprecated_named_route("#{resource.name_prefix}#{resource.plural}", "#{resource.plural}")
0
+ map.deprecated_named_route("formatted_#{resource.name_prefix}#{resource.plural}", "formatted_#{resource.plural}")
0
create_action_options = action_options_for("create", resource)
0
map.connect(resource.path, create_action_options)
0
map.connect("#{resource.path}.:format", create_action_options)
0
@@ -351,11 +391,37 @@ module ActionController
0
actions.each do |action|
0
action_options = action_options_for(action, resource, method)
0
- map.named_route("#{resource.name_prefix}new_#{resource.singular}", resource.new_path, action_options)
0
- map.named_route("formatted_#{resource.name_prefix}new_#{resource.singular}", "#{resource.new_path}.:format", action_options)
0
+ unless resource.old_name_prefix.blank?
0
+ map.deprecated_named_route("new_#{resource.name_prefix}#{resource.singular}", "#{resource.old_name_prefix}new_#{resource.singular}")
0
+ map.deprecated_named_route("formatted_new_#{resource.name_prefix}#{resource.singular}", "formatted_#{resource.old_name_prefix}new_#{resource.singular}")
0
+ if resource.deprecate_name_prefix?
0
+ map.deprecated_named_route("new_#{resource.name_prefix}#{resource.singular}", "new_#{resource.singular}")
0
+ map.deprecated_named_route("formatted_new_#{resource.name_prefix}#{resource.singular}", "formatted_new_#{resource.singular}")
0
+ map.named_route("new_#{resource.name_prefix}#{resource.singular}", resource.new_path, action_options)
0
+ map.named_route("formatted_new_#{resource.name_prefix}#{resource.singular}", "#{resource.new_path}.:format", action_options)
0
- map.named_route("#{resource.name_prefix}#{action}_new_#{resource.singular}", "#{resource.new_path};#{action}", action_options)
0
- map.named_route("formatted_#{resource.name_prefix}#{action}_new_#{resource.singular}", "#{resource.new_path}.:format;#{action}", action_options)
0
+ unless resource.old_name_prefix.blank?
0
+ map.deprecated_named_route("#{action}_new_#{resource.name_prefix}#{resource.singular}", "#{resource.old_name_prefix}#{action}_new_#{resource.singular}")
0
+ map.deprecated_named_route("formatted_#{action}_new_#{resource.name_prefix}#{resource.singular}", "formatted_#{resource.old_name_prefix}#{action}_new_#{resource.singular}")
0
+ if resource.deprecate_name_prefix?
0
+ map.deprecated_named_route("#{action}_new_#{resource.name_prefix}#{resource.singular}", "#{action}_new_#{resource.singular}")
0
+ map.deprecated_named_route("formatted_#{action}_new_#{resource.name_prefix}#{resource.singular}", "formatted_#{action}_new_#{resource.singular}")
0
+ map.named_route("#{action}_new_#{resource.name_prefix}#{resource.singular}", "#{resource.new_path}#{resource.action_separator}#{action}", action_options)
0
+ map.connect("#{resource.new_path};#{action}", action_options)
0
+ map.connect("#{resource.new_path}.:format;#{action}", action_options)
0
+ map.named_route("formatted_#{action}_new_#{resource.name_prefix}#{resource.singular}", "#{resource.new_path}#{resource.action_separator}#{action}.:format", action_options)
0
@@ -365,8 +431,22 @@ module ActionController
0
resource.member_methods.each do |method, actions|
0
actions.each do |action|
0
action_options = action_options_for(action, resource, method)
0
- map.named_route("#{resource.name_prefix}#{action}_#{resource.singular}", "#{resource.member_path};#{action}", action_options)
0
- map.named_route("formatted_#{resource.name_prefix}#{action}_#{resource.singular}", "#{resource.member_path}.:format;#{action}",action_options)
0
+ unless resource.old_name_prefix.blank?
0
+ map.deprecated_named_route("#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.old_name_prefix}#{action}_#{resource.singular}")
0
+ map.deprecated_named_route("formatted_#{action}_#{resource.name_prefix}#{resource.singular}", "formatted_#{resource.old_name_prefix}#{action}_#{resource.singular}")
0
+ if resource.deprecate_name_prefix?
0
+ map.deprecated_named_route("#{action}_#{resource.name_prefix}#{resource.singular}", "#{action}_#{resource.singular}")
0
+ map.deprecated_named_route("formatted_#{action}_#{resource.name_prefix}#{resource.singular}", "formatted_#{action}_#{resource.singular}")
0
+ map.named_route("#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action}", action_options)
0
+ map.connect("#{resource.member_path};#{action}", action_options)
0
+ map.connect("#{resource.member_path}.:format;#{action}", action_options)
0
+ map.named_route("formatted_#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action}.:format", action_options)
0
@@ -374,6 +454,11 @@ module ActionController
0
map.named_route("#{resource.name_prefix}#{resource.singular}", resource.member_path, show_action_options)
0
map.named_route("formatted_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}.:format", show_action_options)
0
+ if resource.deprecate_name_prefix?
0
+ map.deprecated_named_route("#{resource.name_prefix}#{resource.singular}", "#{resource.singular}")
0
+ map.deprecated_named_route("formatted_#{resource.name_prefix}#{resource.singular}", "formatted_#{resource.singular}")
0
update_action_options = action_options_for("update", resource)
0
map.connect(resource.member_path, update_action_options)
0
map.connect("#{resource.member_path}.:format", update_action_options)