actionpack 1.13.6 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +1400 -20
- data/MIT-LICENSE +1 -1
- data/README +5 -5
- data/RUNNING_UNIT_TESTS +4 -5
- data/Rakefile +5 -6
- data/install.rb +2 -2
- data/lib/action_controller.rb +11 -15
- data/lib/action_controller/assertions.rb +12 -25
- data/lib/action_controller/assertions/dom_assertions.rb +18 -4
- data/lib/action_controller/assertions/model_assertions.rb +8 -1
- data/lib/action_controller/assertions/response_assertions.rb +35 -12
- data/lib/action_controller/assertions/routing_assertions.rb +56 -12
- data/lib/action_controller/assertions/selector_assertions.rb +105 -38
- data/lib/action_controller/assertions/tag_assertions.rb +28 -15
- data/lib/action_controller/base.rb +318 -250
- data/lib/action_controller/benchmarking.rb +33 -29
- data/lib/action_controller/caching.rb +130 -64
- data/lib/action_controller/cgi_ext.rb +16 -0
- data/lib/action_controller/cgi_ext/{cookie_performance_fix.rb → cookie.rb} +25 -40
- data/lib/action_controller/cgi_ext/query_extension.rb +22 -0
- data/lib/action_controller/cgi_ext/session.rb +73 -0
- data/lib/action_controller/cgi_ext/stdinput.rb +23 -0
- data/lib/action_controller/cgi_process.rb +34 -57
- data/lib/action_controller/components.rb +19 -36
- data/lib/action_controller/cookies.rb +10 -9
- data/lib/action_controller/dispatcher.rb +195 -0
- data/lib/action_controller/filters.rb +35 -34
- data/lib/action_controller/flash.rb +30 -35
- data/lib/action_controller/helpers.rb +121 -47
- data/lib/action_controller/http_authentication.rb +126 -0
- data/lib/action_controller/integration.rb +105 -101
- data/lib/action_controller/layout.rb +59 -47
- data/lib/action_controller/mime_responds.rb +57 -68
- data/lib/action_controller/mime_type.rb +43 -80
- data/lib/action_controller/mime_types.rb +20 -0
- data/lib/action_controller/polymorphic_routes.rb +88 -0
- data/lib/action_controller/record_identifier.rb +91 -0
- data/lib/action_controller/request.rb +553 -88
- data/lib/action_controller/request_forgery_protection.rb +126 -0
- data/lib/action_controller/request_profiler.rb +138 -0
- data/lib/action_controller/rescue.rb +185 -69
- data/lib/action_controller/resources.rb +211 -172
- data/lib/action_controller/response.rb +49 -8
- data/lib/action_controller/routing.rb +359 -236
- data/lib/action_controller/routing_optimisation.rb +119 -0
- data/lib/action_controller/session/active_record_store.rb +3 -2
- data/lib/action_controller/session/cookie_store.rb +161 -0
- data/lib/action_controller/session/mem_cache_store.rb +9 -16
- data/lib/action_controller/session_management.rb +17 -8
- data/lib/action_controller/streaming.rb +6 -3
- data/lib/action_controller/templates/rescues/_request_and_response.erb +24 -0
- data/lib/action_controller/templates/rescues/{_trace.rhtml → _trace.erb} +0 -0
- data/lib/action_controller/templates/rescues/{diagnostics.rhtml → diagnostics.erb} +2 -2
- data/lib/action_controller/templates/rescues/{layout.rhtml → layout.erb} +0 -0
- data/lib/action_controller/templates/rescues/{missing_template.rhtml → missing_template.erb} +0 -0
- data/lib/action_controller/templates/rescues/{routing_error.rhtml → routing_error.erb} +0 -0
- data/lib/action_controller/templates/rescues/{template_error.rhtml → template_error.erb} +2 -2
- data/lib/action_controller/templates/rescues/{unknown_action.rhtml → unknown_action.erb} +0 -0
- data/lib/action_controller/test_case.rb +53 -0
- data/lib/action_controller/test_process.rb +59 -46
- data/lib/action_controller/url_rewriter.rb +48 -24
- data/lib/action_controller/vendor/html-scanner/html/document.rb +7 -4
- data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +173 -0
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +11 -6
- data/lib/action_controller/verification.rb +27 -21
- data/lib/action_pack.rb +1 -1
- data/lib/action_pack/version.rb +4 -4
- data/lib/action_view.rb +2 -3
- data/lib/action_view/base.rb +218 -63
- data/lib/action_view/compiled_templates.rb +1 -2
- data/lib/action_view/helpers/active_record_helper.rb +35 -17
- data/lib/action_view/helpers/asset_tag_helper.rb +395 -87
- data/lib/action_view/helpers/atom_feed_helper.rb +111 -0
- data/lib/action_view/helpers/benchmark_helper.rb +12 -5
- data/lib/action_view/helpers/cache_helper.rb +29 -0
- data/lib/action_view/helpers/capture_helper.rb +97 -63
- data/lib/action_view/helpers/date_helper.rb +295 -35
- data/lib/action_view/helpers/debug_helper.rb +6 -2
- data/lib/action_view/helpers/form_helper.rb +354 -111
- data/lib/action_view/helpers/form_options_helper.rb +171 -109
- data/lib/action_view/helpers/form_tag_helper.rb +332 -76
- data/lib/action_view/helpers/javascript_helper.rb +35 -11
- data/lib/action_view/helpers/javascripts/controls.js +484 -354
- data/lib/action_view/helpers/javascripts/dragdrop.js +88 -58
- data/lib/action_view/helpers/javascripts/effects.js +396 -364
- data/lib/action_view/helpers/javascripts/prototype.js +2817 -1107
- data/lib/action_view/helpers/number_helper.rb +84 -60
- data/lib/action_view/helpers/prototype_helper.rb +419 -43
- data/lib/action_view/helpers/record_identification_helper.rb +20 -0
- data/lib/action_view/helpers/record_tag_helper.rb +59 -0
- data/lib/action_view/helpers/sanitize_helper.rb +223 -0
- data/lib/action_view/helpers/scriptaculous_helper.rb +63 -4
- data/lib/action_view/helpers/tag_helper.rb +69 -39
- data/lib/action_view/helpers/text_helper.rb +221 -148
- data/lib/action_view/helpers/url_helper.rb +283 -165
- data/lib/action_view/partials.rb +134 -62
- data/lib/action_view/template_error.rb +4 -12
- data/lib/actionpack.rb +1 -0
- data/test/abstract_unit.rb +21 -1
- data/test/action_view_test.rb +26 -0
- data/test/active_record_unit.rb +12 -20
- data/test/activerecord/active_record_store_test.rb +2 -2
- data/test/activerecord/render_partial_with_record_identification_test.rb +74 -0
- data/test/controller/action_pack_assertions_test.rb +21 -152
- data/test/controller/addresses_render_test.rb +2 -7
- data/test/controller/assert_select_test.rb +120 -14
- data/test/controller/base_test.rb +11 -13
- data/test/controller/caching_test.rb +125 -5
- data/test/controller/capture_test.rb +23 -16
- data/test/controller/cgi_test.rb +66 -391
- data/test/controller/components_test.rb +31 -42
- data/test/controller/content_type_test.rb +1 -1
- data/test/controller/cookie_test.rb +42 -14
- data/test/controller/deprecation/deprecated_base_methods_test.rb +1 -42
- data/test/controller/dispatcher_test.rb +123 -0
- data/test/controller/fake_models.rb +5 -0
- data/test/controller/filters_test.rb +44 -7
- data/test/controller/flash_test.rb +46 -2
- data/test/controller/fragment_store_setting_test.rb +10 -8
- data/test/controller/helper_test.rb +19 -2
- data/test/controller/html-scanner/document_test.rb +124 -0
- data/test/controller/html-scanner/node_test.rb +69 -0
- data/test/controller/html-scanner/sanitizer_test.rb +250 -0
- data/test/controller/html-scanner/tag_node_test.rb +239 -0
- data/test/controller/html-scanner/text_node_test.rb +51 -0
- data/test/controller/html-scanner/tokenizer_test.rb +125 -0
- data/test/controller/http_authentication_test.rb +54 -0
- data/test/controller/integration_test.rb +12 -26
- data/test/controller/layout_test.rb +64 -12
- data/test/controller/mime_responds_test.rb +193 -38
- data/test/controller/mime_type_test.rb +30 -8
- data/test/controller/new_render_test.rb +104 -22
- data/test/controller/polymorphic_routes_test.rb +98 -0
- data/test/controller/record_identifier_test.rb +103 -0
- data/test/controller/redirect_test.rb +120 -18
- data/test/controller/render_test.rb +195 -45
- data/test/controller/request_forgery_protection_test.rb +217 -0
- data/test/controller/request_test.rb +545 -27
- data/test/controller/rescue_test.rb +501 -0
- data/test/controller/resources_test.rb +258 -132
- data/test/controller/routing_test.rb +502 -106
- data/test/controller/selector_test.rb +5 -5
- data/test/controller/send_file_test.rb +17 -7
- data/test/controller/session/cookie_store_test.rb +246 -0
- data/test/controller/session/mem_cache_store_test.rb +182 -0
- data/test/controller/session_fixation_test.rb +8 -11
- data/test/controller/session_management_test.rb +7 -7
- data/test/controller/test_test.rb +150 -38
- data/test/controller/url_rewriter_test.rb +87 -12
- data/test/controller/verification_test.rb +11 -0
- data/test/controller/view_paths_test.rb +137 -0
- data/test/controller/webservice_test.rb +11 -75
- data/test/fixtures/addresses/{list.rhtml → list.erb} +0 -0
- data/test/fixtures/db_definitions/sqlite.sql +2 -1
- data/test/fixtures/developer.rb +2 -0
- data/test/fixtures/fun/games/{hello_world.rhtml → hello_world.erb} +0 -0
- data/test/fixtures/helpers/fun/pdf_helper.rb +1 -1
- data/test/fixtures/layout_tests/alt/hello.rhtml +1 -0
- data/test/fixtures/layout_tests/layouts/multiple_extensions.html.erb +1 -0
- data/test/fixtures/layouts/{builder.rxml → builder.builder} +0 -0
- data/test/fixtures/layouts/{standard.rhtml → standard.erb} +0 -0
- data/test/fixtures/layouts/{talk_from_action.rhtml → talk_from_action.erb} +0 -0
- data/test/fixtures/layouts/{yield.rhtml → yield.erb} +0 -0
- data/test/fixtures/multipart/binary_file +0 -0
- data/test/fixtures/multipart/bracketed_param +5 -0
- data/test/fixtures/override/test/hello_world.erb +1 -0
- data/test/fixtures/override2/layouts/test/sub.erb +1 -0
- data/test/fixtures/post_test/layouts/post.html.erb +1 -0
- data/test/fixtures/post_test/layouts/super_post.iphone.erb +1 -0
- data/test/fixtures/post_test/post/index.html.erb +1 -0
- data/test/fixtures/post_test/post/index.iphone.erb +1 -0
- data/test/fixtures/post_test/super_post/index.html.erb +1 -0
- data/test/fixtures/post_test/super_post/index.iphone.erb +1 -0
- data/test/fixtures/public/404.html +1 -0
- data/test/fixtures/public/500.html +1 -0
- data/test/fixtures/public/javascripts/application.js +0 -1
- data/test/fixtures/public/javascripts/bank.js +1 -0
- data/test/fixtures/public/javascripts/robber.js +1 -0
- data/test/fixtures/public/stylesheets/bank.css +1 -0
- data/test/fixtures/public/stylesheets/robber.css +1 -0
- data/test/fixtures/replies.yml +2 -0
- data/test/fixtures/reply.rb +2 -1
- data/test/fixtures/respond_to/{all_types_with_layout.rhtml → all_types_with_layout.html.erb} +0 -0
- data/test/fixtures/respond_to/{all_types_with_layout.rjs → all_types_with_layout.js.rjs} +0 -0
- data/test/fixtures/respond_to/custom_constant_handling_without_block.mobile.erb +1 -0
- data/test/fixtures/respond_to/iphone_with_html_response_type.html.erb +1 -0
- data/test/fixtures/respond_to/iphone_with_html_response_type.iphone.erb +1 -0
- data/test/fixtures/respond_to/layouts/missing.html.erb +1 -0
- data/test/fixtures/respond_to/layouts/standard.html.erb +1 -0
- data/test/fixtures/respond_to/layouts/standard.iphone.erb +1 -0
- data/test/fixtures/respond_to/{using_defaults.rhtml → using_defaults.html.erb} +0 -0
- data/test/fixtures/respond_to/{using_defaults.rjs → using_defaults.js.rjs} +0 -0
- data/test/fixtures/respond_to/{using_defaults.rxml → using_defaults.xml.builder} +0 -0
- data/test/fixtures/respond_to/{using_defaults_with_type_list.rhtml → using_defaults_with_type_list.html.erb} +0 -0
- data/test/fixtures/respond_to/{using_defaults_with_type_list.rjs → using_defaults_with_type_list.js.rjs} +0 -0
- data/test/fixtures/respond_to/{using_defaults_with_type_list.rxml → using_defaults_with_type_list.xml.builder} +0 -0
- data/test/fixtures/scope/test/{modgreet.rhtml → modgreet.erb} +0 -0
- data/test/fixtures/test/{_customer.rhtml → _customer.erb} +0 -0
- data/test/fixtures/test/{_customer_greeting.rhtml → _customer_greeting.erb} +0 -0
- data/test/fixtures/test/_hash_greeting.erb +1 -0
- data/test/fixtures/test/_hash_object.erb +2 -0
- data/test/fixtures/test/{_hello.rxml → _hello.builder} +0 -0
- data/test/fixtures/test/_layout_for_partial.html.erb +3 -0
- data/test/fixtures/test/_partial.erb +1 -0
- data/test/fixtures/test/_partial.html.erb +1 -0
- data/test/fixtures/test/_partial.js.erb +1 -0
- data/test/fixtures/test/_partial_for_use_in_layout.html.erb +1 -0
- data/test/fixtures/test/{_partial_only.rhtml → _partial_only.erb} +0 -0
- data/test/fixtures/test/{_person.rhtml → _person.erb} +0 -0
- data/test/fixtures/test/{action_talk_to_layout.rhtml → action_talk_to_layout.erb} +0 -0
- data/test/fixtures/test/{block_content_for.rhtml → block_content_for.erb} +0 -0
- data/test/fixtures/test/calling_partial_with_layout.html.erb +1 -0
- data/test/fixtures/test/{capturing.rhtml → capturing.erb} +0 -0
- data/test/fixtures/test/{content_for.rhtml → content_for.erb} +0 -0
- data/test/fixtures/test/content_for_concatenated.erb +3 -0
- data/test/fixtures/test/content_for_with_parameter.erb +2 -0
- data/test/fixtures/test/dot.directory/{render_file_with_ivar.rhtml → render_file_with_ivar.erb} +0 -0
- data/test/fixtures/test/{erb_content_for.rhtml → erb_content_for.erb} +0 -0
- data/test/fixtures/test/formatted_html_erb.html.erb +1 -0
- data/test/fixtures/test/formatted_xml_erb.builder +1 -0
- data/test/fixtures/test/formatted_xml_erb.html.erb +1 -0
- data/test/fixtures/test/formatted_xml_erb.xml.erb +1 -0
- data/test/fixtures/test/{greeting.rhtml → greeting.erb} +0 -0
- data/test/fixtures/test/{hello.rxml → hello.builder} +0 -0
- data/test/fixtures/test/{hello_world.rxml → hello_world.builder} +0 -0
- data/test/fixtures/test/{hello_world.rhtml → hello_world.erb} +0 -0
- data/test/fixtures/test/{hello_world_container.rxml → hello_world_container.builder} +0 -0
- data/test/fixtures/test/{hello_world_with_layout_false.rhtml → hello_world_with_layout_false.erb} +0 -0
- data/test/fixtures/test/{hello_xml_world.rxml → hello_xml_world.builder} +0 -0
- data/test/fixtures/test/list.erb +1 -0
- data/test/fixtures/test/{non_erb_block_content_for.rxml → non_erb_block_content_for.builder} +0 -0
- data/test/fixtures/test/{potential_conflicts.rhtml → potential_conflicts.erb} +0 -0
- data/test/fixtures/test/{render_file_with_ivar.rhtml → render_file_with_ivar.erb} +0 -0
- data/test/fixtures/test/{render_file_with_locals.rhtml → render_file_with_locals.erb} +0 -0
- data/test/fixtures/test/{render_to_string_test.rhtml → render_to_string_test.erb} +0 -0
- data/test/fixtures/test/{update_element_with_capture.rhtml → update_element_with_capture.erb} +0 -0
- data/test/fixtures/test/using_layout_around_block.html.erb +1 -0
- data/test/fixtures/topic.rb +1 -1
- data/test/template/active_record_helper_test.rb +67 -20
- data/test/template/asset_tag_helper_test.rb +222 -54
- data/test/template/atom_feed_helper_test.rb +101 -0
- data/test/template/benchmark_helper_test.rb +2 -2
- data/test/template/compiled_templates_test.rb +76 -32
- data/test/template/date_helper_test.rb +125 -9
- data/test/template/form_helper_test.rb +326 -33
- data/test/template/form_options_helper_test.rb +822 -15
- data/test/template/form_tag_helper_test.rb +96 -30
- data/test/template/javascript_helper_test.rb +61 -13
- data/test/template/number_helper_test.rb +12 -11
- data/test/template/prototype_helper_test.rb +185 -24
- data/test/template/sanitize_helper_test.rb +49 -0
- data/test/template/scriptaculous_helper_test.rb +9 -3
- data/test/template/tag_helper_test.rb +13 -2
- data/test/template/text_helper_test.rb +38 -52
- data/test/template/url_helper_test.rb +216 -46
- metadata +144 -116
- data/examples/.htaccess +0 -24
- data/examples/address_book/index.rhtml +0 -33
- data/examples/address_book/layout.rhtml +0 -8
- data/examples/address_book_controller.cgi +0 -9
- data/examples/address_book_controller.fcgi +0 -6
- data/examples/address_book_controller.rb +0 -52
- data/examples/address_book_controller.rbx +0 -4
- data/examples/benchmark.rb +0 -52
- data/examples/benchmark_with_ar.fcgi +0 -89
- data/examples/blog_controller.cgi +0 -53
- data/examples/debate/index.rhtml +0 -14
- data/examples/debate/new_topic.rhtml +0 -22
- data/examples/debate/topic.rhtml +0 -32
- data/examples/debate_controller.cgi +0 -57
- data/lib/action_controller/assertions/deprecated_assertions.rb +0 -228
- data/lib/action_controller/cgi_ext/cgi_ext.rb +0 -36
- data/lib/action_controller/cgi_ext/cgi_methods.rb +0 -211
- data/lib/action_controller/cgi_ext/pstore_performance_fix.rb +0 -30
- data/lib/action_controller/cgi_ext/raw_post_data_fix.rb +0 -95
- data/lib/action_controller/cgi_ext/session_performance_fix.rb +0 -30
- data/lib/action_controller/deprecated_dependencies.rb +0 -65
- data/lib/action_controller/deprecated_redirects.rb +0 -17
- data/lib/action_controller/deprecated_request_methods.rb +0 -34
- data/lib/action_controller/macros/auto_complete.rb +0 -53
- data/lib/action_controller/macros/in_place_editing.rb +0 -33
- data/lib/action_controller/pagination.rb +0 -408
- data/lib/action_controller/scaffolding.rb +0 -189
- data/lib/action_controller/templates/rescues/_request_and_response.rhtml +0 -44
- data/lib/action_controller/templates/scaffolds/edit.rhtml +0 -7
- data/lib/action_controller/templates/scaffolds/layout.rhtml +0 -69
- data/lib/action_controller/templates/scaffolds/list.rhtml +0 -27
- data/lib/action_controller/templates/scaffolds/new.rhtml +0 -6
- data/lib/action_controller/templates/scaffolds/show.rhtml +0 -9
- data/lib/action_controller/vendor/xml_node.rb +0 -97
- data/lib/action_view/helpers/deprecated_helper.rb +0 -37
- data/lib/action_view/helpers/java_script_macros_helper.rb +0 -233
- data/lib/action_view/helpers/pagination_helper.rb +0 -86
- data/test/activerecord/active_record_assertions_test.rb +0 -92
- data/test/activerecord/pagination_test.rb +0 -165
- data/test/controller/deprecated_instance_variables_test.rb +0 -48
- data/test/controller/raw_post_test.rb +0 -68
- data/test/fixtures/deprecated_instance_variables/_cookies_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_cookies_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_flash_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_flash_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_headers_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_headers_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_params_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_params_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_request_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_request_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_response_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_response_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_session_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_session_method.rhtml +0 -1
- data/test/fixtures/respond_to/layouts/standard.rhtml +0 -1
- data/test/fixtures/test/_hash_object.rhtml +0 -1
- data/test/fixtures/test/list.rhtml +0 -1
- data/test/template/deprecated_helper_test.rb +0 -36
- data/test/template/deprecated_instance_variables_test.rb +0 -43
- data/test/template/java_script_macros_helper_test.rb +0 -109
|
@@ -1,14 +1,56 @@
|
|
|
1
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
|
|
2
44
|
module Resources
|
|
3
45
|
class Resource #:nodoc:
|
|
4
46
|
attr_reader :collection_methods, :member_methods, :new_methods
|
|
5
|
-
attr_reader :path_prefix, :
|
|
47
|
+
attr_reader :path_prefix, :name_prefix
|
|
6
48
|
attr_reader :plural, :singular
|
|
7
49
|
attr_reader :options
|
|
8
50
|
|
|
9
51
|
def initialize(entities, options)
|
|
10
|
-
@plural
|
|
11
|
-
@singular
|
|
52
|
+
@plural ||= entities
|
|
53
|
+
@singular ||= options[:singular] || plural.to_s.singularize
|
|
12
54
|
|
|
13
55
|
@options = options
|
|
14
56
|
|
|
@@ -18,7 +60,18 @@ module ActionController
|
|
|
18
60
|
end
|
|
19
61
|
|
|
20
62
|
def controller
|
|
21
|
-
@controller ||= (options[:controller] || plural).to_s
|
|
63
|
+
@controller ||= "#{options[:namespace]}#{(options[:controller] || plural).to_s}"
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def requirements(with_id = false)
|
|
67
|
+
@requirements ||= @options[:requirements] || {}
|
|
68
|
+
@id_requirement ||= { :id => @requirements.delete(:id) || /[^#{Routing::SEPARATORS.join}]+/ }
|
|
69
|
+
|
|
70
|
+
with_id ? @requirements.merge(@id_requirement) : @requirements
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def conditions
|
|
74
|
+
@conditions = @options[:conditions] || {}
|
|
22
75
|
end
|
|
23
76
|
|
|
24
77
|
def path
|
|
@@ -37,26 +90,18 @@ module ActionController
|
|
|
37
90
|
@nesting_path_prefix ||= "#{path}/:#{singular}_id"
|
|
38
91
|
end
|
|
39
92
|
|
|
40
|
-
def deprecate_name_prefix?
|
|
41
|
-
@name_prefix.blank? && !@new_name_prefix.blank?
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def name_prefix
|
|
45
|
-
deprecate_name_prefix? ? @new_name_prefix : @name_prefix
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def old_name_prefix
|
|
49
|
-
@name_prefix
|
|
50
|
-
end
|
|
51
|
-
|
|
52
93
|
def nesting_name_prefix
|
|
53
|
-
"#{
|
|
94
|
+
"#{name_prefix}#{singular}_"
|
|
54
95
|
end
|
|
55
96
|
|
|
56
97
|
def action_separator
|
|
57
98
|
@action_separator ||= Base.resource_action_separator
|
|
58
99
|
end
|
|
59
100
|
|
|
101
|
+
def uncountable?
|
|
102
|
+
@singular.to_s == @plural.to_s
|
|
103
|
+
end
|
|
104
|
+
|
|
60
105
|
protected
|
|
61
106
|
def arrange_actions
|
|
62
107
|
@collection_methods = arrange_actions_by_methods(options.delete(:collection))
|
|
@@ -72,7 +117,6 @@ module ActionController
|
|
|
72
117
|
def set_prefixes
|
|
73
118
|
@path_prefix = options.delete(:path_prefix)
|
|
74
119
|
@name_prefix = options.delete(:name_prefix)
|
|
75
|
-
@new_name_prefix = options.delete(:new_name_prefix)
|
|
76
120
|
end
|
|
77
121
|
|
|
78
122
|
def arrange_actions_by_methods(actions)
|
|
@@ -89,103 +133,111 @@ module ActionController
|
|
|
89
133
|
|
|
90
134
|
class SingletonResource < Resource #:nodoc:
|
|
91
135
|
def initialize(entity, options)
|
|
92
|
-
@
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
add_default_actions
|
|
96
|
-
set_prefixes
|
|
136
|
+
@singular = @plural = entity
|
|
137
|
+
options[:controller] ||= @singular.to_s.pluralize
|
|
138
|
+
super
|
|
97
139
|
end
|
|
98
140
|
|
|
99
141
|
alias_method :member_path, :path
|
|
100
142
|
alias_method :nesting_path_prefix, :path
|
|
101
143
|
end
|
|
102
144
|
|
|
103
|
-
# Creates named routes for implementing verb-oriented controllers
|
|
104
|
-
#
|
|
105
|
-
#
|
|
106
|
-
#
|
|
107
|
-
#
|
|
145
|
+
# Creates named routes for implementing verb-oriented controllers
|
|
146
|
+
# for a collection resource.
|
|
147
|
+
#
|
|
148
|
+
# For example:
|
|
149
|
+
#
|
|
150
|
+
# map.resources :messages
|
|
108
151
|
#
|
|
109
|
-
#
|
|
152
|
+
# will map the following actions in the corresponding controller:
|
|
110
153
|
#
|
|
111
154
|
# class MessagesController < ActionController::Base
|
|
112
155
|
# # GET messages_url
|
|
113
156
|
# def index
|
|
114
157
|
# # return all messages
|
|
115
158
|
# end
|
|
116
|
-
#
|
|
159
|
+
#
|
|
117
160
|
# # GET new_message_url
|
|
118
161
|
# def new
|
|
119
162
|
# # return an HTML form for describing a new message
|
|
120
163
|
# end
|
|
121
|
-
#
|
|
164
|
+
#
|
|
122
165
|
# # POST messages_url
|
|
123
166
|
# def create
|
|
124
167
|
# # create a new message
|
|
125
168
|
# end
|
|
126
|
-
#
|
|
169
|
+
#
|
|
127
170
|
# # GET message_url(:id => 1)
|
|
128
171
|
# def show
|
|
129
172
|
# # find and return a specific message
|
|
130
173
|
# end
|
|
131
|
-
#
|
|
174
|
+
#
|
|
132
175
|
# # GET edit_message_url(:id => 1)
|
|
133
176
|
# def edit
|
|
134
177
|
# # return an HTML form for editing a specific message
|
|
135
178
|
# end
|
|
136
|
-
#
|
|
179
|
+
#
|
|
137
180
|
# # PUT message_url(:id => 1)
|
|
138
181
|
# def update
|
|
139
182
|
# # find and update a specific message
|
|
140
183
|
# end
|
|
141
|
-
#
|
|
184
|
+
#
|
|
142
185
|
# # DELETE message_url(:id => 1)
|
|
143
186
|
# def destroy
|
|
144
187
|
# # delete a specific message
|
|
145
188
|
# end
|
|
146
189
|
# end
|
|
147
|
-
#
|
|
148
|
-
# The #resources method sets HTTP method restrictions on the routes it generates. For example, making an
|
|
149
|
-
# HTTP POST on <tt>new_message_url</tt> will raise a RoutingError exception. The default route in
|
|
150
|
-
# <tt>config/routes.rb</tt> overrides this and allows invalid HTTP methods for resource routes.
|
|
151
|
-
#
|
|
190
|
+
#
|
|
152
191
|
# Along with the routes themselves, #resources generates named routes for use in
|
|
153
192
|
# controllers and views. <tt>map.resources :messages</tt> produces the following named routes and helpers:
|
|
154
|
-
#
|
|
193
|
+
#
|
|
155
194
|
# Named Route Helpers
|
|
156
|
-
#
|
|
195
|
+
# ============ =====================================================
|
|
196
|
+
# messages messages_url, hash_for_messages_url,
|
|
157
197
|
# messages_path, hash_for_messages_path
|
|
158
|
-
#
|
|
198
|
+
#
|
|
199
|
+
# message message_url(id), hash_for_message_url(id),
|
|
159
200
|
# message_path(id), hash_for_message_path(id)
|
|
160
|
-
#
|
|
201
|
+
#
|
|
202
|
+
# new_message new_message_url, hash_for_new_message_url,
|
|
161
203
|
# new_message_path, hash_for_new_message_path
|
|
204
|
+
#
|
|
162
205
|
# edit_message edit_message_url(id), hash_for_edit_message_url(id),
|
|
163
206
|
# edit_message_path(id), hash_for_edit_message_path(id)
|
|
164
207
|
#
|
|
165
|
-
# You can use these helpers instead of #url_for or methods that take #url_for parameters:
|
|
166
|
-
#
|
|
167
|
-
# redirect_to :controller => 'messages', :action => 'index'
|
|
168
|
-
# # becomes
|
|
169
|
-
# redirect_to messages_url
|
|
208
|
+
# You can use these helpers instead of #url_for or methods that take #url_for parameters. For example:
|
|
170
209
|
#
|
|
210
|
+
# redirect_to :controller => 'messages', :action => 'index'
|
|
211
|
+
# # and
|
|
171
212
|
# <%= link_to "edit this message", :controller => 'messages', :action => 'edit', :id => @message.id %>
|
|
172
|
-
#
|
|
213
|
+
#
|
|
214
|
+
# now become:
|
|
215
|
+
#
|
|
216
|
+
# redirect_to messages_url
|
|
217
|
+
# # and
|
|
173
218
|
# <%= link_to "edit this message", edit_message_url(@message) # calls @message.id automatically
|
|
174
219
|
#
|
|
175
220
|
# Since web browsers don't support the PUT and DELETE verbs, you will need to add a parameter '_method' to your
|
|
176
221
|
# form tags. The form helpers make this a little easier. For an update form with a <tt>@message</tt> object:
|
|
177
222
|
#
|
|
178
223
|
# <%= form_tag message_path(@message), :method => :put %>
|
|
179
|
-
#
|
|
180
|
-
# or
|
|
181
|
-
#
|
|
224
|
+
#
|
|
225
|
+
# or
|
|
226
|
+
#
|
|
182
227
|
# <% form_for :message, @message, :url => message_path(@message), :html => {:method => :put} do |f| %>
|
|
183
|
-
#
|
|
184
|
-
# The #resources method accepts
|
|
185
|
-
# routes
|
|
186
|
-
#
|
|
187
|
-
#
|
|
188
|
-
# * <tt>:
|
|
228
|
+
#
|
|
229
|
+
# The #resources method accepts the following options to customize the resulting routes:
|
|
230
|
+
# * <tt>:collection</tt> - add named routes for other actions that operate on the collection.
|
|
231
|
+
# Takes a hash of <tt>#{action} => #{method}</tt>, where method is <tt>:get</tt>/<tt>:post</tt>/<tt>:put</tt>/<tt>:delete</tt>
|
|
232
|
+
# 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.
|
|
233
|
+
# * <tt>:member</tt> - same as :collection, but for actions that operate on a specific member.
|
|
234
|
+
# * <tt>:new</tt> - same as :collection, but for actions that operate on the new resource action.
|
|
235
|
+
# * <tt>:controller</tt> - specify the controller name for the routes.
|
|
236
|
+
# * <tt>:singular</tt> - specify the singular name used in the member routes.
|
|
237
|
+
# * <tt>:requirements</tt> - set custom routing parameter requirements.
|
|
238
|
+
# * <tt>:conditions</tt> - specify custom routing recognition conditions. Resources sets the :method value for the method-specific routes.
|
|
239
|
+
# * <tt>:path_prefix</tt> - set a prefix to the routes with required route variables.
|
|
240
|
+
#
|
|
189
241
|
# Weblog comments usually belong to a post, so you might use resources like:
|
|
190
242
|
#
|
|
191
243
|
# map.resources :articles
|
|
@@ -198,85 +250,102 @@ module ActionController
|
|
|
198
250
|
# end
|
|
199
251
|
#
|
|
200
252
|
# The comment resources work the same, but must now include a value for :article_id.
|
|
201
|
-
#
|
|
253
|
+
#
|
|
202
254
|
# article_comments_url(@article)
|
|
203
255
|
# article_comment_url(@article, @comment)
|
|
204
256
|
#
|
|
205
257
|
# article_comments_url(:article_id => @article)
|
|
206
258
|
# article_comment_url(:article_id => @article, :id => @comment)
|
|
207
259
|
#
|
|
208
|
-
# * <tt>:name_prefix</tt>
|
|
260
|
+
# * <tt>:name_prefix</tt> - define a prefix for all generated routes, usually ending in an underscore.
|
|
209
261
|
# Use this if you have named routes that may clash.
|
|
210
262
|
#
|
|
211
263
|
# map.resources :tags, :path_prefix => '/books/:book_id', :name_prefix => 'book_'
|
|
212
264
|
# map.resources :tags, :path_prefix => '/toys/:toy_id', :name_prefix => 'toy_'
|
|
213
265
|
#
|
|
214
|
-
#
|
|
215
|
-
#
|
|
216
|
-
#
|
|
217
|
-
#
|
|
218
|
-
#
|
|
266
|
+
# You may also use :name_prefix to override the generic named routes in a nested resource:
|
|
267
|
+
#
|
|
268
|
+
# map.resources :articles do |article|
|
|
269
|
+
# article.resources :comments, :name_prefix => nil
|
|
270
|
+
# end
|
|
271
|
+
#
|
|
272
|
+
# This will yield named resources like so:
|
|
273
|
+
#
|
|
274
|
+
# comments_url(@article)
|
|
275
|
+
# comment_url(@article, @comment)
|
|
219
276
|
#
|
|
220
277
|
# If <tt>map.resources</tt> is called with multiple resources, they all get the same options applied.
|
|
221
278
|
#
|
|
222
279
|
# Examples:
|
|
223
|
-
#
|
|
280
|
+
#
|
|
224
281
|
# map.resources :messages, :path_prefix => "/thread/:thread_id"
|
|
225
282
|
# # --> GET /thread/7/messages/1
|
|
226
|
-
#
|
|
283
|
+
#
|
|
227
284
|
# map.resources :messages, :collection => { :rss => :get }
|
|
228
285
|
# # --> GET /messages/rss (maps to the #rss action)
|
|
229
286
|
# # also adds a named route called "rss_messages"
|
|
230
|
-
#
|
|
287
|
+
#
|
|
231
288
|
# map.resources :messages, :member => { :mark => :post }
|
|
232
289
|
# # --> POST /messages/1/mark (maps to the #mark action)
|
|
233
290
|
# # also adds a named route called "mark_message"
|
|
234
|
-
#
|
|
291
|
+
#
|
|
235
292
|
# map.resources :messages, :new => { :preview => :post }
|
|
236
293
|
# # --> POST /messages/new/preview (maps to the #preview action)
|
|
237
294
|
# # also adds a named route called "preview_new_message"
|
|
238
|
-
#
|
|
295
|
+
#
|
|
239
296
|
# map.resources :messages, :new => { :new => :any, :preview => :post }
|
|
240
297
|
# # --> POST /messages/new/preview (maps to the #preview action)
|
|
241
298
|
# # also adds a named route called "preview_new_message"
|
|
242
299
|
# # --> /messages/new can be invoked via any request method
|
|
243
|
-
#
|
|
300
|
+
#
|
|
244
301
|
# map.resources :messages, :controller => "categories",
|
|
245
302
|
# :path_prefix => "/category/:category_id",
|
|
246
303
|
# :name_prefix => "category_"
|
|
247
304
|
# # --> GET /categories/7/messages/1
|
|
248
305
|
# # has named route "category_message"
|
|
306
|
+
#
|
|
307
|
+
# The #resources method sets HTTP method restrictions on the routes it generates. For example, making an
|
|
308
|
+
# HTTP POST on <tt>new_message_url</tt> will raise a RoutingError exception. The default route in
|
|
309
|
+
# <tt>config/routes.rb</tt> overrides this and allows invalid HTTP methods for resource routes.
|
|
249
310
|
def resources(*entities, &block)
|
|
250
|
-
options = entities.
|
|
251
|
-
entities.each { |entity| map_resource
|
|
311
|
+
options = entities.extract_options!
|
|
312
|
+
entities.each { |entity| map_resource(entity, options.dup, &block) }
|
|
252
313
|
end
|
|
253
314
|
|
|
254
|
-
# Creates named routes for implementing verb-oriented controllers for a singleton resource.
|
|
255
|
-
# A singleton resource is global to
|
|
256
|
-
#
|
|
257
|
-
#
|
|
315
|
+
# Creates named routes for implementing verb-oriented controllers for a singleton resource.
|
|
316
|
+
# A singleton resource is global to its current context. For unnested singleton resources,
|
|
317
|
+
# the resource is global to the current user visiting the application, such as a user's
|
|
318
|
+
# /account profile. For nested singleton resources, the resource is global to its parent
|
|
319
|
+
# resource, such as a <tt>projects</tt> resource that <tt>has_one :project_manager</tt>.
|
|
320
|
+
# The <tt>project_manager</tt> should be mapped as a singleton resource under <tt>projects</tt>:
|
|
321
|
+
#
|
|
322
|
+
# map.resources :projects do |project|
|
|
323
|
+
# project.resource :project_manager
|
|
324
|
+
# end
|
|
325
|
+
#
|
|
258
326
|
# See map.resources for general conventions. These are the main differences:
|
|
259
|
-
#
|
|
260
|
-
#
|
|
261
|
-
#
|
|
262
|
-
#
|
|
263
|
-
# - When nesting singleton resources, only the singular name is used as the path prefix (example: 'account/messages/1')
|
|
327
|
+
# * A singular name is given to map.resource. The default controller name is still taken from the plural name.
|
|
328
|
+
# * To specify a custom plural name, use the :plural option. There is no :singular option.
|
|
329
|
+
# * No default index route is created for the singleton resource controller.
|
|
330
|
+
# * When nesting singleton resources, only the singular name is used as the path prefix (example: 'account/messages/1')
|
|
264
331
|
#
|
|
265
|
-
#
|
|
332
|
+
# For example:
|
|
266
333
|
#
|
|
267
|
-
# map.resource :account
|
|
334
|
+
# map.resource :account
|
|
268
335
|
#
|
|
269
|
-
#
|
|
270
|
-
# # POST account_url
|
|
271
|
-
# def create
|
|
272
|
-
# # create an account
|
|
273
|
-
# end
|
|
336
|
+
# maps these actions in the Accounts controller:
|
|
274
337
|
#
|
|
338
|
+
# class AccountsController < ActionController::Base
|
|
275
339
|
# # GET new_account_url
|
|
276
340
|
# def new
|
|
277
341
|
# # return an HTML form for describing the new account
|
|
278
342
|
# end
|
|
279
343
|
#
|
|
344
|
+
# # POST account_url
|
|
345
|
+
# def create
|
|
346
|
+
# # create an account
|
|
347
|
+
# end
|
|
348
|
+
#
|
|
280
349
|
# # GET account_url
|
|
281
350
|
# def show
|
|
282
351
|
# # find and return the account
|
|
@@ -298,17 +367,23 @@ module ActionController
|
|
|
298
367
|
# end
|
|
299
368
|
# end
|
|
300
369
|
#
|
|
301
|
-
# Along with the routes themselves, #resource generates named routes for
|
|
302
|
-
# controllers and views. <tt>map.resource :account</tt> produces
|
|
303
|
-
#
|
|
370
|
+
# Along with the routes themselves, #resource generates named routes for
|
|
371
|
+
# use in controllers and views. <tt>map.resource :account</tt> produces
|
|
372
|
+
# these named routes and helpers:
|
|
373
|
+
#
|
|
304
374
|
# Named Route Helpers
|
|
305
|
-
#
|
|
375
|
+
# ============ =============================================
|
|
376
|
+
# account account_url, hash_for_account_url,
|
|
306
377
|
# account_path, hash_for_account_path
|
|
378
|
+
#
|
|
379
|
+
# new_account new_account_url, hash_for_new_account_url,
|
|
380
|
+
# new_account_path, hash_for_new_account_path
|
|
381
|
+
#
|
|
307
382
|
# edit_account edit_account_url, hash_for_edit_account_url,
|
|
308
383
|
# edit_account_path, hash_for_edit_account_path
|
|
309
384
|
def resource(*entities, &block)
|
|
310
|
-
options = entities.
|
|
311
|
-
entities.each { |entity| map_singleton_resource
|
|
385
|
+
options = entities.extract_options!
|
|
386
|
+
entities.each { |entity| map_singleton_resource(entity, options.dup, &block) }
|
|
312
387
|
end
|
|
313
388
|
|
|
314
389
|
private
|
|
@@ -321,8 +396,10 @@ module ActionController
|
|
|
321
396
|
map_new_actions(map, resource)
|
|
322
397
|
map_member_actions(map, resource)
|
|
323
398
|
|
|
399
|
+
map_associations(resource, options)
|
|
400
|
+
|
|
324
401
|
if block_given?
|
|
325
|
-
with_options(:path_prefix => resource.nesting_path_prefix, :
|
|
402
|
+
with_options(:path_prefix => resource.nesting_path_prefix, :name_prefix => resource.nesting_name_prefix, :namespace => options[:namespace], &block)
|
|
326
403
|
end
|
|
327
404
|
end
|
|
328
405
|
end
|
|
@@ -336,30 +413,32 @@ module ActionController
|
|
|
336
413
|
map_new_actions(map, resource)
|
|
337
414
|
map_member_actions(map, resource)
|
|
338
415
|
|
|
416
|
+
map_associations(resource, options)
|
|
417
|
+
|
|
339
418
|
if block_given?
|
|
340
|
-
with_options(:path_prefix => resource.nesting_path_prefix, :
|
|
419
|
+
with_options(:path_prefix => resource.nesting_path_prefix, :name_prefix => resource.nesting_name_prefix, :namespace => options[:namespace], &block)
|
|
341
420
|
end
|
|
342
421
|
end
|
|
343
422
|
end
|
|
344
423
|
|
|
424
|
+
def map_associations(resource, options)
|
|
425
|
+
path_prefix = "#{options.delete(:path_prefix)}#{resource.nesting_path_prefix}"
|
|
426
|
+
name_prefix = "#{options.delete(:name_prefix)}#{resource.nesting_name_prefix}"
|
|
427
|
+
|
|
428
|
+
Array(options[:has_many]).each do |association|
|
|
429
|
+
resources(association, :path_prefix => path_prefix, :name_prefix => name_prefix, :namespace => options[:namespace])
|
|
430
|
+
end
|
|
431
|
+
|
|
432
|
+
Array(options[:has_one]).each do |association|
|
|
433
|
+
resource(association, :path_prefix => path_prefix, :name_prefix => name_prefix, :namespace => options[:namespace])
|
|
434
|
+
end
|
|
435
|
+
end
|
|
436
|
+
|
|
345
437
|
def map_collection_actions(map, resource)
|
|
346
438
|
resource.collection_methods.each do |method, actions|
|
|
347
439
|
actions.each do |action|
|
|
348
440
|
action_options = action_options_for(action, resource, method)
|
|
349
|
-
|
|
350
|
-
unless resource.old_name_prefix.blank?
|
|
351
|
-
map.deprecated_named_route("#{action}_#{resource.name_prefix}#{resource.plural}", "#{resource.old_name_prefix}#{action}_#{resource.plural}")
|
|
352
|
-
map.deprecated_named_route("formatted_#{action}_#{resource.name_prefix}#{resource.plural}", "formatted_#{resource.old_name_prefix}#{action}_#{resource.plural}")
|
|
353
|
-
end
|
|
354
|
-
|
|
355
|
-
if resource.deprecate_name_prefix?
|
|
356
|
-
map.deprecated_named_route("#{action}_#{resource.name_prefix}#{resource.plural}", "#{action}_#{resource.plural}")
|
|
357
|
-
map.deprecated_named_route("formatted_#{action}_#{resource.name_prefix}#{resource.plural}", "formatted_#{action}_#{resource.plural}")
|
|
358
|
-
end
|
|
359
|
-
|
|
360
441
|
map.named_route("#{action}_#{resource.name_prefix}#{resource.plural}", "#{resource.path}#{resource.action_separator}#{action}", action_options)
|
|
361
|
-
map.connect("#{resource.path};#{action}", action_options)
|
|
362
|
-
map.connect("#{resource.path}.:format;#{action}", action_options)
|
|
363
442
|
map.named_route("formatted_#{action}_#{resource.name_prefix}#{resource.plural}", "#{resource.path}#{resource.action_separator}#{action}.:format", action_options)
|
|
364
443
|
end
|
|
365
444
|
end
|
|
@@ -367,14 +446,15 @@ module ActionController
|
|
|
367
446
|
|
|
368
447
|
def map_default_collection_actions(map, resource)
|
|
369
448
|
index_action_options = action_options_for("index", resource)
|
|
370
|
-
|
|
371
|
-
map.named_route("formatted_#{resource.name_prefix}#{resource.plural}", "#{resource.path}.:format", index_action_options)
|
|
449
|
+
index_route_name = "#{resource.name_prefix}#{resource.plural}"
|
|
372
450
|
|
|
373
|
-
if resource.
|
|
374
|
-
|
|
375
|
-
map.deprecated_named_route("formatted_#{resource.name_prefix}#{resource.plural}", "formatted_#{resource.plural}")
|
|
451
|
+
if resource.uncountable?
|
|
452
|
+
index_route_name << "_index"
|
|
376
453
|
end
|
|
377
454
|
|
|
455
|
+
map.named_route(index_route_name, resource.path, index_action_options)
|
|
456
|
+
map.named_route("formatted_#{index_route_name}", "#{resource.path}.:format", index_action_options)
|
|
457
|
+
|
|
378
458
|
create_action_options = action_options_for("create", resource)
|
|
379
459
|
map.connect(resource.path, create_action_options)
|
|
380
460
|
map.connect("#{resource.path}.:format", create_action_options)
|
|
@@ -391,37 +471,11 @@ module ActionController
|
|
|
391
471
|
actions.each do |action|
|
|
392
472
|
action_options = action_options_for(action, resource, method)
|
|
393
473
|
if action == :new
|
|
394
|
-
|
|
395
|
-
unless resource.old_name_prefix.blank?
|
|
396
|
-
map.deprecated_named_route("new_#{resource.name_prefix}#{resource.singular}", "#{resource.old_name_prefix}new_#{resource.singular}")
|
|
397
|
-
map.deprecated_named_route("formatted_new_#{resource.name_prefix}#{resource.singular}", "formatted_#{resource.old_name_prefix}new_#{resource.singular}")
|
|
398
|
-
end
|
|
399
|
-
|
|
400
|
-
if resource.deprecate_name_prefix?
|
|
401
|
-
map.deprecated_named_route("new_#{resource.name_prefix}#{resource.singular}", "new_#{resource.singular}")
|
|
402
|
-
map.deprecated_named_route("formatted_new_#{resource.name_prefix}#{resource.singular}", "formatted_new_#{resource.singular}")
|
|
403
|
-
end
|
|
404
|
-
|
|
405
474
|
map.named_route("new_#{resource.name_prefix}#{resource.singular}", resource.new_path, action_options)
|
|
406
475
|
map.named_route("formatted_new_#{resource.name_prefix}#{resource.singular}", "#{resource.new_path}.:format", action_options)
|
|
407
|
-
|
|
408
476
|
else
|
|
409
|
-
|
|
410
|
-
unless resource.old_name_prefix.blank?
|
|
411
|
-
map.deprecated_named_route("#{action}_new_#{resource.name_prefix}#{resource.singular}", "#{resource.old_name_prefix}#{action}_new_#{resource.singular}")
|
|
412
|
-
map.deprecated_named_route("formatted_#{action}_new_#{resource.name_prefix}#{resource.singular}", "formatted_#{resource.old_name_prefix}#{action}_new_#{resource.singular}")
|
|
413
|
-
end
|
|
414
|
-
|
|
415
|
-
if resource.deprecate_name_prefix?
|
|
416
|
-
map.deprecated_named_route("#{action}_new_#{resource.name_prefix}#{resource.singular}", "#{action}_new_#{resource.singular}")
|
|
417
|
-
map.deprecated_named_route("formatted_#{action}_new_#{resource.name_prefix}#{resource.singular}", "formatted_#{action}_new_#{resource.singular}")
|
|
418
|
-
end
|
|
419
|
-
|
|
420
477
|
map.named_route("#{action}_new_#{resource.name_prefix}#{resource.singular}", "#{resource.new_path}#{resource.action_separator}#{action}", action_options)
|
|
421
|
-
map.connect("#{resource.new_path};#{action}", action_options)
|
|
422
|
-
map.connect("#{resource.new_path}.:format;#{action}", action_options)
|
|
423
478
|
map.named_route("formatted_#{action}_new_#{resource.name_prefix}#{resource.singular}", "#{resource.new_path}#{resource.action_separator}#{action}.:format", action_options)
|
|
424
|
-
|
|
425
479
|
end
|
|
426
480
|
end
|
|
427
481
|
end
|
|
@@ -431,22 +485,8 @@ module ActionController
|
|
|
431
485
|
resource.member_methods.each do |method, actions|
|
|
432
486
|
actions.each do |action|
|
|
433
487
|
action_options = action_options_for(action, resource, method)
|
|
434
|
-
|
|
435
|
-
unless resource.old_name_prefix.blank?
|
|
436
|
-
map.deprecated_named_route("#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.old_name_prefix}#{action}_#{resource.singular}")
|
|
437
|
-
map.deprecated_named_route("formatted_#{action}_#{resource.name_prefix}#{resource.singular}", "formatted_#{resource.old_name_prefix}#{action}_#{resource.singular}")
|
|
438
|
-
end
|
|
439
|
-
|
|
440
|
-
if resource.deprecate_name_prefix?
|
|
441
|
-
map.deprecated_named_route("#{action}_#{resource.name_prefix}#{resource.singular}", "#{action}_#{resource.singular}")
|
|
442
|
-
map.deprecated_named_route("formatted_#{action}_#{resource.name_prefix}#{resource.singular}", "formatted_#{action}_#{resource.singular}")
|
|
443
|
-
end
|
|
444
|
-
|
|
445
488
|
map.named_route("#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action}", action_options)
|
|
446
|
-
map.
|
|
447
|
-
map.connect("#{resource.member_path}.:format;#{action}", action_options)
|
|
448
|
-
map.named_route("formatted_#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action}.:format", action_options)
|
|
449
|
-
|
|
489
|
+
map.named_route("formatted_#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action}.:format",action_options)
|
|
450
490
|
end
|
|
451
491
|
end
|
|
452
492
|
|
|
@@ -454,11 +494,6 @@ module ActionController
|
|
|
454
494
|
map.named_route("#{resource.name_prefix}#{resource.singular}", resource.member_path, show_action_options)
|
|
455
495
|
map.named_route("formatted_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}.:format", show_action_options)
|
|
456
496
|
|
|
457
|
-
if resource.deprecate_name_prefix?
|
|
458
|
-
map.deprecated_named_route("#{resource.name_prefix}#{resource.singular}", "#{resource.singular}")
|
|
459
|
-
map.deprecated_named_route("formatted_#{resource.name_prefix}#{resource.singular}", "formatted_#{resource.singular}")
|
|
460
|
-
end
|
|
461
|
-
|
|
462
497
|
update_action_options = action_options_for("update", resource)
|
|
463
498
|
map.connect(resource.member_path, update_action_options)
|
|
464
499
|
map.connect("#{resource.member_path}.:format", update_action_options)
|
|
@@ -468,23 +503,27 @@ module ActionController
|
|
|
468
503
|
map.connect("#{resource.member_path}.:format", destroy_action_options)
|
|
469
504
|
end
|
|
470
505
|
|
|
471
|
-
def
|
|
472
|
-
{
|
|
506
|
+
def add_conditions_for(conditions, method)
|
|
507
|
+
returning({:conditions => conditions.dup}) do |options|
|
|
508
|
+
options[:conditions][:method] = method unless method == :any
|
|
509
|
+
end
|
|
473
510
|
end
|
|
474
511
|
|
|
475
512
|
def action_options_for(action, resource, method = nil)
|
|
476
513
|
default_options = { :action => action.to_s }
|
|
477
|
-
require_id = resource.kind_of?(SingletonResource)
|
|
514
|
+
require_id = !resource.kind_of?(SingletonResource)
|
|
478
515
|
case default_options[:action]
|
|
479
|
-
when "index", "new"
|
|
480
|
-
when "create"
|
|
481
|
-
when "show", "edit"
|
|
482
|
-
when "update"
|
|
483
|
-
when "destroy"
|
|
484
|
-
else default_options.merge(
|
|
516
|
+
when "index", "new"; default_options.merge(add_conditions_for(resource.conditions, method || :get)).merge(resource.requirements)
|
|
517
|
+
when "create"; default_options.merge(add_conditions_for(resource.conditions, method || :post)).merge(resource.requirements)
|
|
518
|
+
when "show", "edit"; default_options.merge(add_conditions_for(resource.conditions, method || :get)).merge(resource.requirements(require_id))
|
|
519
|
+
when "update"; default_options.merge(add_conditions_for(resource.conditions, method || :put)).merge(resource.requirements(require_id))
|
|
520
|
+
when "destroy"; default_options.merge(add_conditions_for(resource.conditions, method || :delete)).merge(resource.requirements(require_id))
|
|
521
|
+
else default_options.merge(add_conditions_for(resource.conditions, method)).merge(resource.requirements)
|
|
485
522
|
end
|
|
486
523
|
end
|
|
487
524
|
end
|
|
488
525
|
end
|
|
489
526
|
|
|
490
|
-
ActionController::Routing::RouteSet::Mapper
|
|
527
|
+
class ActionController::Routing::RouteSet::Mapper
|
|
528
|
+
include ActionController::Resources
|
|
529
|
+
end
|