Froze rails gems
[depot.git] / vendor / rails / actionpack / lib / action_controller / resources.rb
1 module ActionController
2 # == Overview
3 #
4 # ActionController::Resources are a way of defining RESTful \resources. A RESTful \resource, in basic terms,
5 # is something that can be pointed at and it will respond with a representation of the data requested.
6 # In real terms this could mean a user with a browser requests an HTML page, or that a desktop application
7 # requests XML data.
8 #
9 # RESTful design is based on the assumption that there are four generic verbs that a user of an
10 # application can request from a \resource (the noun).
11 #
12 # \Resources can be requested using four basic HTTP verbs (GET, POST, PUT, DELETE), the method used
13 # denotes the type of action that should take place.
14 #
15 # === The Different Methods and their Usage
16 #
17 # * GET - Requests for a \resource, no saving or editing of a \resource should occur in a GET request.
18 # * POST - Creation of \resources.
19 # * PUT - Editing of attributes on a \resource.
20 # * DELETE - Deletion of a \resource.
21 #
22 # === Examples
23 #
24 # # A GET request on the Posts resource is asking for all Posts
25 # GET /posts
26 #
27 # # A GET request on a single Post resource is asking for that particular Post
28 # GET /posts/1
29 #
30 # # A POST request on the Posts resource is asking for a Post to be created with the supplied details
31 # POST /posts # with => { :post => { :title => "My Whizzy New Post", :body => "I've got a brand new combine harvester" } }
32 #
33 # # A PUT request on a single Post resource is asking for a Post to be updated
34 # PUT /posts # with => { :id => 1, :post => { :title => "Changed Whizzy Title" } }
35 #
36 # # A DELETE request on a single Post resource is asking for it to be deleted
37 # DELETE /posts # with => { :id => 1 }
38 #
39 # By using the REST convention, users of our application can assume certain things about how the data
40 # is requested and how it is returned. Rails simplifies the routing part of RESTful design by
41 # supplying you with methods to create them in your routes.rb file.
42 #
43 # Read more about REST at http://en.wikipedia.org/wiki/Representational_State_Transfer
44 module Resources
45 INHERITABLE_OPTIONS = :namespace, :shallow, :actions
46
47 class Resource #:nodoc:
48 DEFAULT_ACTIONS = :index, :create, :new, :edit, :show, :update, :destroy
49
50 attr_reader :collection_methods, :member_methods, :new_methods
51 attr_reader :path_prefix, :name_prefix, :path_segment
52 attr_reader :plural, :singular
53 attr_reader :options
54
55 def initialize(entities, options)
56 @plural ||= entities
57 @singular ||= options[:singular] || plural.to_s.singularize
58 @path_segment = options.delete(:as) || @plural
59
60 @options = options
61
62 arrange_actions
63 add_default_actions
64 set_allowed_actions
65 set_prefixes
66 end
67
68 def controller
69 @controller ||= "#{options[:namespace]}#{(options[:controller] || plural).to_s}"
70 end
71
72 def requirements(with_id = false)
73 @requirements ||= @options[:requirements] || {}
74 @id_requirement ||= { :id => @requirements.delete(:id) || /[^#{Routing::SEPARATORS.join}]+/ }
75
76 with_id ? @requirements.merge(@id_requirement) : @requirements
77 end
78
79 def conditions
80 @conditions ||= @options[:conditions] || {}
81 end
82
83 def path
84 @path ||= "#{path_prefix}/#{path_segment}"
85 end
86
87 def new_path
88 new_action = self.options[:path_names][:new] if self.options[:path_names]
89 new_action ||= Base.resources_path_names[:new]
90 @new_path ||= "#{path}/#{new_action}"
91 end
92
93 def shallow_path_prefix
94 @shallow_path_prefix ||= "#{path_prefix unless @options[:shallow]}"
95 end
96
97 def member_path
98 @member_path ||= "#{shallow_path_prefix}/#{path_segment}/:id"
99 end
100
101 def nesting_path_prefix
102 @nesting_path_prefix ||= "#{shallow_path_prefix}/#{path_segment}/:#{singular}_id"
103 end
104
105 def shallow_name_prefix
106 @shallow_name_prefix ||= "#{name_prefix unless @options[:shallow]}"
107 end
108
109 def nesting_name_prefix
110 "#{shallow_name_prefix}#{singular}_"
111 end
112
113 def action_separator
114 @action_separator ||= Base.resource_action_separator
115 end
116
117 def uncountable?
118 @singular.to_s == @plural.to_s
119 end
120
121 def has_action?(action)
122 !DEFAULT_ACTIONS.include?(action) || @options[:actions].nil? || @options[:actions].include?(action)
123 end
124
125 protected
126 def arrange_actions
127 @collection_methods = arrange_actions_by_methods(options.delete(:collection))
128 @member_methods = arrange_actions_by_methods(options.delete(:member))
129 @new_methods = arrange_actions_by_methods(options.delete(:new))
130 end
131
132 def add_default_actions
133 add_default_action(member_methods, :get, :edit)
134 add_default_action(new_methods, :get, :new)
135 end
136
137 def set_allowed_actions
138 only = @options.delete(:only)
139 except = @options.delete(:except)
140
141 if only && except
142 raise ArgumentError, 'Please supply either :only or :except, not both.'
143 elsif only == :all || except == :none
144 options[:actions] = DEFAULT_ACTIONS
145 elsif only == :none || except == :all
146 options[:actions] = []
147 elsif only
148 options[:actions] = DEFAULT_ACTIONS & Array(only).map(&:to_sym)
149 elsif except
150 options[:actions] = DEFAULT_ACTIONS - Array(except).map(&:to_sym)
151 else
152 # leave options[:actions] alone
153 end
154 end
155
156 def set_prefixes
157 @path_prefix = options.delete(:path_prefix)
158 @name_prefix = options.delete(:name_prefix)
159 end
160
161 def arrange_actions_by_methods(actions)
162 (actions || {}).inject({}) do |flipped_hash, (key, value)|
163 (flipped_hash[value] ||= []) << key
164 flipped_hash
165 end
166 end
167
168 def add_default_action(collection, method, action)
169 (collection[method] ||= []).unshift(action)
170 end
171 end
172
173 class SingletonResource < Resource #:nodoc:
174 def initialize(entity, options)
175 @singular = @plural = entity
176 options[:controller] ||= @singular.to_s.pluralize
177 super
178 end
179
180 alias_method :shallow_path_prefix, :path_prefix
181 alias_method :shallow_name_prefix, :name_prefix
182 alias_method :member_path, :path
183 alias_method :nesting_path_prefix, :path
184 end
185
186 # Creates named routes for implementing verb-oriented controllers
187 # for a collection \resource.
188 #
189 # For example:
190 #
191 # map.resources :messages
192 #
193 # will map the following actions in the corresponding controller:
194 #
195 # class MessagesController < ActionController::Base
196 # # GET messages_url
197 # def index
198 # # return all messages
199 # end
200 #
201 # # GET new_message_url
202 # def new
203 # # return an HTML form for describing a new message
204 # end
205 #
206 # # POST messages_url
207 # def create
208 # # create a new message
209 # end
210 #
211 # # GET message_url(:id => 1)
212 # def show
213 # # find and return a specific message
214 # end
215 #
216 # # GET edit_message_url(:id => 1)
217 # def edit
218 # # return an HTML form for editing a specific message
219 # end
220 #
221 # # PUT message_url(:id => 1)
222 # def update
223 # # find and update a specific message
224 # end
225 #
226 # # DELETE message_url(:id => 1)
227 # def destroy
228 # # delete a specific message
229 # end
230 # end
231 #
232 # Along with the routes themselves, +resources+ generates named routes for use in
233 # controllers and views. <tt>map.resources :messages</tt> produces the following named routes and helpers:
234 #
235 # Named Route Helpers
236 # ============ =====================================================
237 # messages messages_url, hash_for_messages_url,
238 # messages_path, hash_for_messages_path
239 #
240 # message message_url(id), hash_for_message_url(id),
241 # message_path(id), hash_for_message_path(id)
242 #
243 # new_message new_message_url, hash_for_new_message_url,
244 # new_message_path, hash_for_new_message_path
245 #
246 # edit_message edit_message_url(id), hash_for_edit_message_url(id),
247 # edit_message_path(id), hash_for_edit_message_path(id)
248 #
249 # You can use these helpers instead of +url_for+ or methods that take +url_for+ parameters. For example:
250 #
251 # redirect_to :controller => 'messages', :action => 'index'
252 # # and
253 # <%= link_to "edit this message", :controller => 'messages', :action => 'edit', :id => @message.id %>
254 #
255 # now become:
256 #
257 # redirect_to messages_url
258 # # and
259 # <%= link_to "edit this message", edit_message_url(@message) # calls @message.id automatically
260 #
261 # Since web browsers don't support the PUT and DELETE verbs, you will need to add a parameter '_method' to your
262 # form tags. The form helpers make this a little easier. For an update form with a <tt>@message</tt> object:
263 #
264 # <%= form_tag message_path(@message), :method => :put %>
265 #
266 # or
267 #
268 # <% form_for :message, @message, :url => message_path(@message), :html => {:method => :put} do |f| %>
269 #
270 # or
271 #
272 # <% form_for @message do |f| %>
273 #
274 # which takes into account whether <tt>@message</tt> is a new record or not and generates the
275 # path and method accordingly.
276 #
277 # The +resources+ method accepts the following options to customize the resulting routes:
278 # * <tt>:collection</tt> - Add named routes for other actions that operate on the collection.
279 # Takes a hash of <tt>#{action} => #{method}</tt>, where method is <tt>:get</tt>/<tt>:post</tt>/<tt>:put</tt>/<tt>:delete</tt>,
280 # an array of any of the previous, or <tt>:any</tt> if the method does not matter.
281 # These routes map to a URL like /messages/rss, with a route of +rss_messages_url+.
282 # * <tt>:member</tt> - Same as <tt>:collection</tt>, but for actions that operate on a specific member.
283 # * <tt>:new</tt> - Same as <tt>:collection</tt>, but for actions that operate on the new \resource action.
284 # * <tt>:controller</tt> - Specify the controller name for the routes.
285 # * <tt>:singular</tt> - Specify the singular name used in the member routes.
286 # * <tt>:requirements</tt> - Set custom routing parameter requirements.
287 # * <tt>:conditions</tt> - Specify custom routing recognition conditions. \Resources sets the <tt>:method</tt> value for the method-specific routes.
288 # * <tt>:as</tt> - Specify a different \resource name to use in the URL path. For example:
289 # # products_path == '/productos'
290 # map.resources :products, :as => 'productos' do |product|
291 # # product_reviews_path(product) == '/productos/1234/comentarios'
292 # product.resources :product_reviews, :as => 'comentarios'
293 # end
294 #
295 # * <tt>:has_one</tt> - Specify nested \resources, this is a shorthand for mapping singleton \resources beneath the current.
296 # * <tt>:has_many</tt> - Same has <tt>:has_one</tt>, but for plural \resources.
297 #
298 # You may directly specify the routing association with +has_one+ and +has_many+ like:
299 #
300 # map.resources :notes, :has_one => :author, :has_many => [:comments, :attachments]
301 #
302 # This is the same as:
303 #
304 # map.resources :notes do |notes|
305 # notes.resource :author
306 # notes.resources :comments
307 # notes.resources :attachments
308 # end
309 #
310 # * <tt>:path_names</tt> - Specify different names for the 'new' and 'edit' actions. For example:
311 # # new_products_path == '/productos/nuevo'
312 # map.resources :products, :as => 'productos', :path_names => { :new => 'nuevo', :edit => 'editar' }
313 #
314 # You can also set default action names from an environment, like this:
315 # config.action_controller.resources_path_names = { :new => 'nuevo', :edit => 'editar' }
316 #
317 # * <tt>:path_prefix</tt> - Set a prefix to the routes with required route variables.
318 #
319 # Weblog comments usually belong to a post, so you might use +resources+ like:
320 #
321 # map.resources :articles
322 # map.resources :comments, :path_prefix => '/articles/:article_id'
323 #
324 # You can nest +resources+ calls to set this automatically:
325 #
326 # map.resources :articles do |article|
327 # article.resources :comments
328 # end
329 #
330 # The comment \resources work the same, but must now include a value for <tt>:article_id</tt>.
331 #
332 # article_comments_url(@article)
333 # article_comment_url(@article, @comment)
334 #
335 # article_comments_url(:article_id => @article)
336 # article_comment_url(:article_id => @article, :id => @comment)
337 #
338 # If you don't want to load all objects from the database you might want to use the <tt>article_id</tt> directly:
339 #
340 # articles_comments_url(@comment.article_id, @comment)
341 #
342 # * <tt>:name_prefix</tt> - Define a prefix for all generated routes, usually ending in an underscore.
343 # Use this if you have named routes that may clash.
344 #
345 # map.resources :tags, :path_prefix => '/books/:book_id', :name_prefix => 'book_'
346 # map.resources :tags, :path_prefix => '/toys/:toy_id', :name_prefix => 'toy_'
347 #
348 # You may also use <tt>:name_prefix</tt> to override the generic named routes in a nested \resource:
349 #
350 # map.resources :articles do |article|
351 # article.resources :comments, :name_prefix => nil
352 # end
353 #
354 # This will yield named \resources like so:
355 #
356 # comments_url(@article)
357 # comment_url(@article, @comment)
358 #
359 # * <tt>:shallow</tt> - If true, paths for nested resources which reference a specific member
360 # (ie. those with an :id parameter) will not use the parent path prefix or name prefix.
361 #
362 # The <tt>:shallow</tt> option is inherited by any nested resource(s).
363 #
364 # For example, 'users', 'posts' and 'comments' all use shallow paths with the following nested resources:
365 #
366 # map.resources :users, :shallow => true do |user|
367 # user.resources :posts do |post|
368 # post.resources :comments
369 # end
370 # end
371 # # --> GET /users/1/posts (maps to the PostsController#index action as usual)
372 # # also adds the usual named route called "user_posts"
373 # # --> GET /posts/2 (maps to the PostsController#show action as if it were not nested)
374 # # also adds the named route called "post"
375 # # --> GET /posts/2/comments (maps to the CommentsController#index action)
376 # # also adds the named route called "post_comments"
377 # # --> GET /comments/2 (maps to the CommentsController#show action as if it were not nested)
378 # # also adds the named route called "comment"
379 #
380 # You may also use <tt>:shallow</tt> in combination with the +has_one+ and +has_many+ shorthand notations like:
381 #
382 # map.resources :users, :has_many => { :posts => :comments }, :shallow => true
383 #
384 # * <tt>:only</tt> and <tt>:except</tt> - Specify which of the seven default actions should be routed to.
385 #
386 # <tt>:only</tt> and <tt>:except</tt> may be set to <tt>:all</tt>, <tt>:none</tt>, an action name or a
387 # list of action names. By default, routes are generated for all seven actions.
388 #
389 # For example:
390 #
391 # map.resources :posts, :only => [:index, :show] do |post|
392 # post.resources :comments, :except => [:update, :destroy]
393 # end
394 # # --> GET /posts (maps to the PostsController#index action)
395 # # --> POST /posts (fails)
396 # # --> GET /posts/1 (maps to the PostsController#show action)
397 # # --> DELETE /posts/1 (fails)
398 # # --> POST /posts/1/comments (maps to the CommentsController#create action)
399 # # --> PUT /posts/1/comments/1 (fails)
400 #
401 # The <tt>:only</tt> and <tt>:except</tt> options are inherited by any nested resource(s).
402 #
403 # If <tt>map.resources</tt> is called with multiple resources, they all get the same options applied.
404 #
405 # Examples:
406 #
407 # map.resources :messages, :path_prefix => "/thread/:thread_id"
408 # # --> GET /thread/7/messages/1
409 #
410 # map.resources :messages, :collection => { :rss => :get }
411 # # --> GET /messages/rss (maps to the #rss action)
412 # # also adds a named route called "rss_messages"
413 #
414 # map.resources :messages, :member => { :mark => :post }
415 # # --> POST /messages/1/mark (maps to the #mark action)
416 # # also adds a named route called "mark_message"
417 #
418 # map.resources :messages, :new => { :preview => :post }
419 # # --> POST /messages/new/preview (maps to the #preview action)
420 # # also adds a named route called "preview_new_message"
421 #
422 # map.resources :messages, :new => { :new => :any, :preview => :post }
423 # # --> POST /messages/new/preview (maps to the #preview action)
424 # # also adds a named route called "preview_new_message"
425 # # --> /messages/new can be invoked via any request method
426 #
427 # map.resources :messages, :controller => "categories",
428 # :path_prefix => "/category/:category_id",
429 # :name_prefix => "category_"
430 # # --> GET /categories/7/messages/1
431 # # has named route "category_message"
432 #
433 # The +resources+ method sets HTTP method restrictions on the routes it generates. For example, making an
434 # HTTP POST on <tt>new_message_url</tt> will raise a RoutingError exception. The default route in
435 # <tt>config/routes.rb</tt> overrides this and allows invalid HTTP methods for \resource routes.
436 def resources(*entities, &block)
437 options = entities.extract_options!
438 entities.each { |entity| map_resource(entity, options.dup, &block) }
439 end
440
441 # Creates named routes for implementing verb-oriented controllers for a singleton \resource.
442 # A singleton \resource is global to its current context. For unnested singleton \resources,
443 # the \resource is global to the current user visiting the application, such as a user's
444 # <tt>/account</tt> profile. For nested singleton \resources, the \resource is global to its parent
445 # \resource, such as a <tt>projects</tt> \resource that <tt>has_one :project_manager</tt>.
446 # The <tt>project_manager</tt> should be mapped as a singleton \resource under <tt>projects</tt>:
447 #
448 # map.resources :projects do |project|
449 # project.resource :project_manager
450 # end
451 #
452 # See +resources+ for general conventions. These are the main differences:
453 # * A singular name is given to <tt>map.resource</tt>. The default controller name is still taken from the plural name.
454 # * To specify a custom plural name, use the <tt>:plural</tt> option. There is no <tt>:singular</tt> option.
455 # * No default index route is created for the singleton \resource controller.
456 # * When nesting singleton \resources, only the singular name is used as the path prefix (example: 'account/messages/1')
457 #
458 # For example:
459 #
460 # map.resource :account
461 #
462 # maps these actions in the Accounts controller:
463 #
464 # class AccountsController < ActionController::Base
465 # # GET new_account_url
466 # def new
467 # # return an HTML form for describing the new account
468 # end
469 #
470 # # POST account_url
471 # def create
472 # # create an account
473 # end
474 #
475 # # GET account_url
476 # def show
477 # # find and return the account
478 # end
479 #
480 # # GET edit_account_url
481 # def edit
482 # # return an HTML form for editing the account
483 # end
484 #
485 # # PUT account_url
486 # def update
487 # # find and update the account
488 # end
489 #
490 # # DELETE account_url
491 # def destroy
492 # # delete the account
493 # end
494 # end
495 #
496 # Along with the routes themselves, +resource+ generates named routes for
497 # use in controllers and views. <tt>map.resource :account</tt> produces
498 # these named routes and helpers:
499 #
500 # Named Route Helpers
501 # ============ =============================================
502 # account account_url, hash_for_account_url,
503 # account_path, hash_for_account_path
504 #
505 # new_account new_account_url, hash_for_new_account_url,
506 # new_account_path, hash_for_new_account_path
507 #
508 # edit_account edit_account_url, hash_for_edit_account_url,
509 # edit_account_path, hash_for_edit_account_path
510 def resource(*entities, &block)
511 options = entities.extract_options!
512 entities.each { |entity| map_singleton_resource(entity, options.dup, &block) }
513 end
514
515 private
516 def map_resource(entities, options = {}, &block)
517 resource = Resource.new(entities, options)
518
519 with_options :controller => resource.controller do |map|
520 map_collection_actions(map, resource)
521 map_default_collection_actions(map, resource)
522 map_new_actions(map, resource)
523 map_member_actions(map, resource)
524
525 map_associations(resource, options)
526
527 if block_given?
528 with_options(options.slice(*INHERITABLE_OPTIONS).merge(:path_prefix => resource.nesting_path_prefix, :name_prefix => resource.nesting_name_prefix), &block)
529 end
530 end
531 end
532
533 def map_singleton_resource(entities, options = {}, &block)
534 resource = SingletonResource.new(entities, options)
535
536 with_options :controller => resource.controller do |map|
537 map_collection_actions(map, resource)
538 map_default_singleton_actions(map, resource)
539 map_new_actions(map, resource)
540 map_member_actions(map, resource)
541
542 map_associations(resource, options)
543
544 if block_given?
545 with_options(options.slice(*INHERITABLE_OPTIONS).merge(:path_prefix => resource.nesting_path_prefix, :name_prefix => resource.nesting_name_prefix), &block)
546 end
547 end
548 end
549
550 def map_associations(resource, options)
551 map_has_many_associations(resource, options.delete(:has_many), options) if options[:has_many]
552
553 path_prefix = "#{options.delete(:path_prefix)}#{resource.nesting_path_prefix}"
554 name_prefix = "#{options.delete(:name_prefix)}#{resource.nesting_name_prefix}"
555
556 Array(options[:has_one]).each do |association|
557 resource(association, options.slice(*INHERITABLE_OPTIONS).merge(:path_prefix => path_prefix, :name_prefix => name_prefix))
558 end
559 end
560
561 def map_has_many_associations(resource, associations, options)
562 case associations
563 when Hash
564 associations.each do |association,has_many|
565 map_has_many_associations(resource, association, options.merge(:has_many => has_many))
566 end
567 when Array
568 associations.each do |association|
569 map_has_many_associations(resource, association, options)
570 end
571 when Symbol, String
572 resources(associations, options.slice(*INHERITABLE_OPTIONS).merge(:path_prefix => resource.nesting_path_prefix, :name_prefix => resource.nesting_name_prefix, :has_many => options[:has_many]))
573 else
574 end
575 end
576
577 def map_collection_actions(map, resource)
578 resource.collection_methods.each do |method, actions|
579 actions.each do |action|
580 [method].flatten.each do |m|
581 map_resource_routes(map, resource, action, "#{resource.path}#{resource.action_separator}#{action}", "#{action}_#{resource.name_prefix}#{resource.plural}", m)
582 end
583 end
584 end
585 end
586
587 def map_default_collection_actions(map, resource)
588 index_route_name = "#{resource.name_prefix}#{resource.plural}"
589
590 if resource.uncountable?
591 index_route_name << "_index"
592 end
593
594 map_resource_routes(map, resource, :index, resource.path, index_route_name)
595 map_resource_routes(map, resource, :create, resource.path, index_route_name)
596 end
597
598 def map_default_singleton_actions(map, resource)
599 map_resource_routes(map, resource, :create, resource.path, "#{resource.shallow_name_prefix}#{resource.singular}")
600 end
601
602 def map_new_actions(map, resource)
603 resource.new_methods.each do |method, actions|
604 actions.each do |action|
605 route_path = resource.new_path
606 route_name = "new_#{resource.name_prefix}#{resource.singular}"
607
608 unless action == :new
609 route_path = "#{route_path}#{resource.action_separator}#{action}"
610 route_name = "#{action}_#{route_name}"
611 end
612
613 map_resource_routes(map, resource, action, route_path, route_name, method)
614 end
615 end
616 end
617
618 def map_member_actions(map, resource)
619 resource.member_methods.each do |method, actions|
620 actions.each do |action|
621 [method].flatten.each do |m|
622 action_path = resource.options[:path_names][action] if resource.options[:path_names].is_a?(Hash)
623 action_path ||= Base.resources_path_names[action] || action
624
625 map_resource_routes(map, resource, action, "#{resource.member_path}#{resource.action_separator}#{action_path}", "#{action}_#{resource.shallow_name_prefix}#{resource.singular}", m)
626 end
627 end
628 end
629
630 route_path = "#{resource.shallow_name_prefix}#{resource.singular}"
631 map_resource_routes(map, resource, :show, resource.member_path, route_path)
632 map_resource_routes(map, resource, :update, resource.member_path, route_path)
633 map_resource_routes(map, resource, :destroy, resource.member_path, route_path)
634 end
635
636 def map_resource_routes(map, resource, action, route_path, route_name = nil, method = nil)
637 if resource.has_action?(action)
638 action_options = action_options_for(action, resource, method)
639 formatted_route_path = "#{route_path}.:format"
640
641 if route_name && @set.named_routes[route_name.to_sym].nil?
642 map.named_route(route_name, route_path, action_options)
643 map.named_route("formatted_#{route_name}", formatted_route_path, action_options)
644 else
645 map.connect(route_path, action_options)
646 map.connect(formatted_route_path, action_options)
647 end
648 end
649 end
650
651 def add_conditions_for(conditions, method)
652 returning({:conditions => conditions.dup}) do |options|
653 options[:conditions][:method] = method unless method == :any
654 end
655 end
656
657 def action_options_for(action, resource, method = nil)
658 default_options = { :action => action.to_s }
659 require_id = !resource.kind_of?(SingletonResource)
660
661 case default_options[:action]
662 when "index", "new"; default_options.merge(add_conditions_for(resource.conditions, method || :get)).merge(resource.requirements)
663 when "create"; default_options.merge(add_conditions_for(resource.conditions, method || :post)).merge(resource.requirements)
664 when "show", "edit"; default_options.merge(add_conditions_for(resource.conditions, method || :get)).merge(resource.requirements(require_id))
665 when "update"; default_options.merge(add_conditions_for(resource.conditions, method || :put)).merge(resource.requirements(require_id))
666 when "destroy"; default_options.merge(add_conditions_for(resource.conditions, method || :delete)).merge(resource.requirements(require_id))
667 else default_options.merge(add_conditions_for(resource.conditions, method)).merge(resource.requirements)
668 end
669 end
670 end
671 end
672
673 class ActionController::Routing::RouteSet::Mapper
674 include ActionController::Resources
675 end