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.
Files changed (317) hide show
  1. data/CHANGELOG +1400 -20
  2. data/MIT-LICENSE +1 -1
  3. data/README +5 -5
  4. data/RUNNING_UNIT_TESTS +4 -5
  5. data/Rakefile +5 -6
  6. data/install.rb +2 -2
  7. data/lib/action_controller.rb +11 -15
  8. data/lib/action_controller/assertions.rb +12 -25
  9. data/lib/action_controller/assertions/dom_assertions.rb +18 -4
  10. data/lib/action_controller/assertions/model_assertions.rb +8 -1
  11. data/lib/action_controller/assertions/response_assertions.rb +35 -12
  12. data/lib/action_controller/assertions/routing_assertions.rb +56 -12
  13. data/lib/action_controller/assertions/selector_assertions.rb +105 -38
  14. data/lib/action_controller/assertions/tag_assertions.rb +28 -15
  15. data/lib/action_controller/base.rb +318 -250
  16. data/lib/action_controller/benchmarking.rb +33 -29
  17. data/lib/action_controller/caching.rb +130 -64
  18. data/lib/action_controller/cgi_ext.rb +16 -0
  19. data/lib/action_controller/cgi_ext/{cookie_performance_fix.rb → cookie.rb} +25 -40
  20. data/lib/action_controller/cgi_ext/query_extension.rb +22 -0
  21. data/lib/action_controller/cgi_ext/session.rb +73 -0
  22. data/lib/action_controller/cgi_ext/stdinput.rb +23 -0
  23. data/lib/action_controller/cgi_process.rb +34 -57
  24. data/lib/action_controller/components.rb +19 -36
  25. data/lib/action_controller/cookies.rb +10 -9
  26. data/lib/action_controller/dispatcher.rb +195 -0
  27. data/lib/action_controller/filters.rb +35 -34
  28. data/lib/action_controller/flash.rb +30 -35
  29. data/lib/action_controller/helpers.rb +121 -47
  30. data/lib/action_controller/http_authentication.rb +126 -0
  31. data/lib/action_controller/integration.rb +105 -101
  32. data/lib/action_controller/layout.rb +59 -47
  33. data/lib/action_controller/mime_responds.rb +57 -68
  34. data/lib/action_controller/mime_type.rb +43 -80
  35. data/lib/action_controller/mime_types.rb +20 -0
  36. data/lib/action_controller/polymorphic_routes.rb +88 -0
  37. data/lib/action_controller/record_identifier.rb +91 -0
  38. data/lib/action_controller/request.rb +553 -88
  39. data/lib/action_controller/request_forgery_protection.rb +126 -0
  40. data/lib/action_controller/request_profiler.rb +138 -0
  41. data/lib/action_controller/rescue.rb +185 -69
  42. data/lib/action_controller/resources.rb +211 -172
  43. data/lib/action_controller/response.rb +49 -8
  44. data/lib/action_controller/routing.rb +359 -236
  45. data/lib/action_controller/routing_optimisation.rb +119 -0
  46. data/lib/action_controller/session/active_record_store.rb +3 -2
  47. data/lib/action_controller/session/cookie_store.rb +161 -0
  48. data/lib/action_controller/session/mem_cache_store.rb +9 -16
  49. data/lib/action_controller/session_management.rb +17 -8
  50. data/lib/action_controller/streaming.rb +6 -3
  51. data/lib/action_controller/templates/rescues/_request_and_response.erb +24 -0
  52. data/lib/action_controller/templates/rescues/{_trace.rhtml → _trace.erb} +0 -0
  53. data/lib/action_controller/templates/rescues/{diagnostics.rhtml → diagnostics.erb} +2 -2
  54. data/lib/action_controller/templates/rescues/{layout.rhtml → layout.erb} +0 -0
  55. data/lib/action_controller/templates/rescues/{missing_template.rhtml → missing_template.erb} +0 -0
  56. data/lib/action_controller/templates/rescues/{routing_error.rhtml → routing_error.erb} +0 -0
  57. data/lib/action_controller/templates/rescues/{template_error.rhtml → template_error.erb} +2 -2
  58. data/lib/action_controller/templates/rescues/{unknown_action.rhtml → unknown_action.erb} +0 -0
  59. data/lib/action_controller/test_case.rb +53 -0
  60. data/lib/action_controller/test_process.rb +59 -46
  61. data/lib/action_controller/url_rewriter.rb +48 -24
  62. data/lib/action_controller/vendor/html-scanner/html/document.rb +7 -4
  63. data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +173 -0
  64. data/lib/action_controller/vendor/html-scanner/html/selector.rb +11 -6
  65. data/lib/action_controller/verification.rb +27 -21
  66. data/lib/action_pack.rb +1 -1
  67. data/lib/action_pack/version.rb +4 -4
  68. data/lib/action_view.rb +2 -3
  69. data/lib/action_view/base.rb +218 -63
  70. data/lib/action_view/compiled_templates.rb +1 -2
  71. data/lib/action_view/helpers/active_record_helper.rb +35 -17
  72. data/lib/action_view/helpers/asset_tag_helper.rb +395 -87
  73. data/lib/action_view/helpers/atom_feed_helper.rb +111 -0
  74. data/lib/action_view/helpers/benchmark_helper.rb +12 -5
  75. data/lib/action_view/helpers/cache_helper.rb +29 -0
  76. data/lib/action_view/helpers/capture_helper.rb +97 -63
  77. data/lib/action_view/helpers/date_helper.rb +295 -35
  78. data/lib/action_view/helpers/debug_helper.rb +6 -2
  79. data/lib/action_view/helpers/form_helper.rb +354 -111
  80. data/lib/action_view/helpers/form_options_helper.rb +171 -109
  81. data/lib/action_view/helpers/form_tag_helper.rb +332 -76
  82. data/lib/action_view/helpers/javascript_helper.rb +35 -11
  83. data/lib/action_view/helpers/javascripts/controls.js +484 -354
  84. data/lib/action_view/helpers/javascripts/dragdrop.js +88 -58
  85. data/lib/action_view/helpers/javascripts/effects.js +396 -364
  86. data/lib/action_view/helpers/javascripts/prototype.js +2817 -1107
  87. data/lib/action_view/helpers/number_helper.rb +84 -60
  88. data/lib/action_view/helpers/prototype_helper.rb +419 -43
  89. data/lib/action_view/helpers/record_identification_helper.rb +20 -0
  90. data/lib/action_view/helpers/record_tag_helper.rb +59 -0
  91. data/lib/action_view/helpers/sanitize_helper.rb +223 -0
  92. data/lib/action_view/helpers/scriptaculous_helper.rb +63 -4
  93. data/lib/action_view/helpers/tag_helper.rb +69 -39
  94. data/lib/action_view/helpers/text_helper.rb +221 -148
  95. data/lib/action_view/helpers/url_helper.rb +283 -165
  96. data/lib/action_view/partials.rb +134 -62
  97. data/lib/action_view/template_error.rb +4 -12
  98. data/lib/actionpack.rb +1 -0
  99. data/test/abstract_unit.rb +21 -1
  100. data/test/action_view_test.rb +26 -0
  101. data/test/active_record_unit.rb +12 -20
  102. data/test/activerecord/active_record_store_test.rb +2 -2
  103. data/test/activerecord/render_partial_with_record_identification_test.rb +74 -0
  104. data/test/controller/action_pack_assertions_test.rb +21 -152
  105. data/test/controller/addresses_render_test.rb +2 -7
  106. data/test/controller/assert_select_test.rb +120 -14
  107. data/test/controller/base_test.rb +11 -13
  108. data/test/controller/caching_test.rb +125 -5
  109. data/test/controller/capture_test.rb +23 -16
  110. data/test/controller/cgi_test.rb +66 -391
  111. data/test/controller/components_test.rb +31 -42
  112. data/test/controller/content_type_test.rb +1 -1
  113. data/test/controller/cookie_test.rb +42 -14
  114. data/test/controller/deprecation/deprecated_base_methods_test.rb +1 -42
  115. data/test/controller/dispatcher_test.rb +123 -0
  116. data/test/controller/fake_models.rb +5 -0
  117. data/test/controller/filters_test.rb +44 -7
  118. data/test/controller/flash_test.rb +46 -2
  119. data/test/controller/fragment_store_setting_test.rb +10 -8
  120. data/test/controller/helper_test.rb +19 -2
  121. data/test/controller/html-scanner/document_test.rb +124 -0
  122. data/test/controller/html-scanner/node_test.rb +69 -0
  123. data/test/controller/html-scanner/sanitizer_test.rb +250 -0
  124. data/test/controller/html-scanner/tag_node_test.rb +239 -0
  125. data/test/controller/html-scanner/text_node_test.rb +51 -0
  126. data/test/controller/html-scanner/tokenizer_test.rb +125 -0
  127. data/test/controller/http_authentication_test.rb +54 -0
  128. data/test/controller/integration_test.rb +12 -26
  129. data/test/controller/layout_test.rb +64 -12
  130. data/test/controller/mime_responds_test.rb +193 -38
  131. data/test/controller/mime_type_test.rb +30 -8
  132. data/test/controller/new_render_test.rb +104 -22
  133. data/test/controller/polymorphic_routes_test.rb +98 -0
  134. data/test/controller/record_identifier_test.rb +103 -0
  135. data/test/controller/redirect_test.rb +120 -18
  136. data/test/controller/render_test.rb +195 -45
  137. data/test/controller/request_forgery_protection_test.rb +217 -0
  138. data/test/controller/request_test.rb +545 -27
  139. data/test/controller/rescue_test.rb +501 -0
  140. data/test/controller/resources_test.rb +258 -132
  141. data/test/controller/routing_test.rb +502 -106
  142. data/test/controller/selector_test.rb +5 -5
  143. data/test/controller/send_file_test.rb +17 -7
  144. data/test/controller/session/cookie_store_test.rb +246 -0
  145. data/test/controller/session/mem_cache_store_test.rb +182 -0
  146. data/test/controller/session_fixation_test.rb +8 -11
  147. data/test/controller/session_management_test.rb +7 -7
  148. data/test/controller/test_test.rb +150 -38
  149. data/test/controller/url_rewriter_test.rb +87 -12
  150. data/test/controller/verification_test.rb +11 -0
  151. data/test/controller/view_paths_test.rb +137 -0
  152. data/test/controller/webservice_test.rb +11 -75
  153. data/test/fixtures/addresses/{list.rhtml → list.erb} +0 -0
  154. data/test/fixtures/db_definitions/sqlite.sql +2 -1
  155. data/test/fixtures/developer.rb +2 -0
  156. data/test/fixtures/fun/games/{hello_world.rhtml → hello_world.erb} +0 -0
  157. data/test/fixtures/helpers/fun/pdf_helper.rb +1 -1
  158. data/test/fixtures/layout_tests/alt/hello.rhtml +1 -0
  159. data/test/fixtures/layout_tests/layouts/multiple_extensions.html.erb +1 -0
  160. data/test/fixtures/layouts/{builder.rxml → builder.builder} +0 -0
  161. data/test/fixtures/layouts/{standard.rhtml → standard.erb} +0 -0
  162. data/test/fixtures/layouts/{talk_from_action.rhtml → talk_from_action.erb} +0 -0
  163. data/test/fixtures/layouts/{yield.rhtml → yield.erb} +0 -0
  164. data/test/fixtures/multipart/binary_file +0 -0
  165. data/test/fixtures/multipart/bracketed_param +5 -0
  166. data/test/fixtures/override/test/hello_world.erb +1 -0
  167. data/test/fixtures/override2/layouts/test/sub.erb +1 -0
  168. data/test/fixtures/post_test/layouts/post.html.erb +1 -0
  169. data/test/fixtures/post_test/layouts/super_post.iphone.erb +1 -0
  170. data/test/fixtures/post_test/post/index.html.erb +1 -0
  171. data/test/fixtures/post_test/post/index.iphone.erb +1 -0
  172. data/test/fixtures/post_test/super_post/index.html.erb +1 -0
  173. data/test/fixtures/post_test/super_post/index.iphone.erb +1 -0
  174. data/test/fixtures/public/404.html +1 -0
  175. data/test/fixtures/public/500.html +1 -0
  176. data/test/fixtures/public/javascripts/application.js +0 -1
  177. data/test/fixtures/public/javascripts/bank.js +1 -0
  178. data/test/fixtures/public/javascripts/robber.js +1 -0
  179. data/test/fixtures/public/stylesheets/bank.css +1 -0
  180. data/test/fixtures/public/stylesheets/robber.css +1 -0
  181. data/test/fixtures/replies.yml +2 -0
  182. data/test/fixtures/reply.rb +2 -1
  183. data/test/fixtures/respond_to/{all_types_with_layout.rhtml → all_types_with_layout.html.erb} +0 -0
  184. data/test/fixtures/respond_to/{all_types_with_layout.rjs → all_types_with_layout.js.rjs} +0 -0
  185. data/test/fixtures/respond_to/custom_constant_handling_without_block.mobile.erb +1 -0
  186. data/test/fixtures/respond_to/iphone_with_html_response_type.html.erb +1 -0
  187. data/test/fixtures/respond_to/iphone_with_html_response_type.iphone.erb +1 -0
  188. data/test/fixtures/respond_to/layouts/missing.html.erb +1 -0
  189. data/test/fixtures/respond_to/layouts/standard.html.erb +1 -0
  190. data/test/fixtures/respond_to/layouts/standard.iphone.erb +1 -0
  191. data/test/fixtures/respond_to/{using_defaults.rhtml → using_defaults.html.erb} +0 -0
  192. data/test/fixtures/respond_to/{using_defaults.rjs → using_defaults.js.rjs} +0 -0
  193. data/test/fixtures/respond_to/{using_defaults.rxml → using_defaults.xml.builder} +0 -0
  194. data/test/fixtures/respond_to/{using_defaults_with_type_list.rhtml → using_defaults_with_type_list.html.erb} +0 -0
  195. data/test/fixtures/respond_to/{using_defaults_with_type_list.rjs → using_defaults_with_type_list.js.rjs} +0 -0
  196. data/test/fixtures/respond_to/{using_defaults_with_type_list.rxml → using_defaults_with_type_list.xml.builder} +0 -0
  197. data/test/fixtures/scope/test/{modgreet.rhtml → modgreet.erb} +0 -0
  198. data/test/fixtures/test/{_customer.rhtml → _customer.erb} +0 -0
  199. data/test/fixtures/test/{_customer_greeting.rhtml → _customer_greeting.erb} +0 -0
  200. data/test/fixtures/test/_hash_greeting.erb +1 -0
  201. data/test/fixtures/test/_hash_object.erb +2 -0
  202. data/test/fixtures/test/{_hello.rxml → _hello.builder} +0 -0
  203. data/test/fixtures/test/_layout_for_partial.html.erb +3 -0
  204. data/test/fixtures/test/_partial.erb +1 -0
  205. data/test/fixtures/test/_partial.html.erb +1 -0
  206. data/test/fixtures/test/_partial.js.erb +1 -0
  207. data/test/fixtures/test/_partial_for_use_in_layout.html.erb +1 -0
  208. data/test/fixtures/test/{_partial_only.rhtml → _partial_only.erb} +0 -0
  209. data/test/fixtures/test/{_person.rhtml → _person.erb} +0 -0
  210. data/test/fixtures/test/{action_talk_to_layout.rhtml → action_talk_to_layout.erb} +0 -0
  211. data/test/fixtures/test/{block_content_for.rhtml → block_content_for.erb} +0 -0
  212. data/test/fixtures/test/calling_partial_with_layout.html.erb +1 -0
  213. data/test/fixtures/test/{capturing.rhtml → capturing.erb} +0 -0
  214. data/test/fixtures/test/{content_for.rhtml → content_for.erb} +0 -0
  215. data/test/fixtures/test/content_for_concatenated.erb +3 -0
  216. data/test/fixtures/test/content_for_with_parameter.erb +2 -0
  217. data/test/fixtures/test/dot.directory/{render_file_with_ivar.rhtml → render_file_with_ivar.erb} +0 -0
  218. data/test/fixtures/test/{erb_content_for.rhtml → erb_content_for.erb} +0 -0
  219. data/test/fixtures/test/formatted_html_erb.html.erb +1 -0
  220. data/test/fixtures/test/formatted_xml_erb.builder +1 -0
  221. data/test/fixtures/test/formatted_xml_erb.html.erb +1 -0
  222. data/test/fixtures/test/formatted_xml_erb.xml.erb +1 -0
  223. data/test/fixtures/test/{greeting.rhtml → greeting.erb} +0 -0
  224. data/test/fixtures/test/{hello.rxml → hello.builder} +0 -0
  225. data/test/fixtures/test/{hello_world.rxml → hello_world.builder} +0 -0
  226. data/test/fixtures/test/{hello_world.rhtml → hello_world.erb} +0 -0
  227. data/test/fixtures/test/{hello_world_container.rxml → hello_world_container.builder} +0 -0
  228. data/test/fixtures/test/{hello_world_with_layout_false.rhtml → hello_world_with_layout_false.erb} +0 -0
  229. data/test/fixtures/test/{hello_xml_world.rxml → hello_xml_world.builder} +0 -0
  230. data/test/fixtures/test/list.erb +1 -0
  231. data/test/fixtures/test/{non_erb_block_content_for.rxml → non_erb_block_content_for.builder} +0 -0
  232. data/test/fixtures/test/{potential_conflicts.rhtml → potential_conflicts.erb} +0 -0
  233. data/test/fixtures/test/{render_file_with_ivar.rhtml → render_file_with_ivar.erb} +0 -0
  234. data/test/fixtures/test/{render_file_with_locals.rhtml → render_file_with_locals.erb} +0 -0
  235. data/test/fixtures/test/{render_to_string_test.rhtml → render_to_string_test.erb} +0 -0
  236. data/test/fixtures/test/{update_element_with_capture.rhtml → update_element_with_capture.erb} +0 -0
  237. data/test/fixtures/test/using_layout_around_block.html.erb +1 -0
  238. data/test/fixtures/topic.rb +1 -1
  239. data/test/template/active_record_helper_test.rb +67 -20
  240. data/test/template/asset_tag_helper_test.rb +222 -54
  241. data/test/template/atom_feed_helper_test.rb +101 -0
  242. data/test/template/benchmark_helper_test.rb +2 -2
  243. data/test/template/compiled_templates_test.rb +76 -32
  244. data/test/template/date_helper_test.rb +125 -9
  245. data/test/template/form_helper_test.rb +326 -33
  246. data/test/template/form_options_helper_test.rb +822 -15
  247. data/test/template/form_tag_helper_test.rb +96 -30
  248. data/test/template/javascript_helper_test.rb +61 -13
  249. data/test/template/number_helper_test.rb +12 -11
  250. data/test/template/prototype_helper_test.rb +185 -24
  251. data/test/template/sanitize_helper_test.rb +49 -0
  252. data/test/template/scriptaculous_helper_test.rb +9 -3
  253. data/test/template/tag_helper_test.rb +13 -2
  254. data/test/template/text_helper_test.rb +38 -52
  255. data/test/template/url_helper_test.rb +216 -46
  256. metadata +144 -116
  257. data/examples/.htaccess +0 -24
  258. data/examples/address_book/index.rhtml +0 -33
  259. data/examples/address_book/layout.rhtml +0 -8
  260. data/examples/address_book_controller.cgi +0 -9
  261. data/examples/address_book_controller.fcgi +0 -6
  262. data/examples/address_book_controller.rb +0 -52
  263. data/examples/address_book_controller.rbx +0 -4
  264. data/examples/benchmark.rb +0 -52
  265. data/examples/benchmark_with_ar.fcgi +0 -89
  266. data/examples/blog_controller.cgi +0 -53
  267. data/examples/debate/index.rhtml +0 -14
  268. data/examples/debate/new_topic.rhtml +0 -22
  269. data/examples/debate/topic.rhtml +0 -32
  270. data/examples/debate_controller.cgi +0 -57
  271. data/lib/action_controller/assertions/deprecated_assertions.rb +0 -228
  272. data/lib/action_controller/cgi_ext/cgi_ext.rb +0 -36
  273. data/lib/action_controller/cgi_ext/cgi_methods.rb +0 -211
  274. data/lib/action_controller/cgi_ext/pstore_performance_fix.rb +0 -30
  275. data/lib/action_controller/cgi_ext/raw_post_data_fix.rb +0 -95
  276. data/lib/action_controller/cgi_ext/session_performance_fix.rb +0 -30
  277. data/lib/action_controller/deprecated_dependencies.rb +0 -65
  278. data/lib/action_controller/deprecated_redirects.rb +0 -17
  279. data/lib/action_controller/deprecated_request_methods.rb +0 -34
  280. data/lib/action_controller/macros/auto_complete.rb +0 -53
  281. data/lib/action_controller/macros/in_place_editing.rb +0 -33
  282. data/lib/action_controller/pagination.rb +0 -408
  283. data/lib/action_controller/scaffolding.rb +0 -189
  284. data/lib/action_controller/templates/rescues/_request_and_response.rhtml +0 -44
  285. data/lib/action_controller/templates/scaffolds/edit.rhtml +0 -7
  286. data/lib/action_controller/templates/scaffolds/layout.rhtml +0 -69
  287. data/lib/action_controller/templates/scaffolds/list.rhtml +0 -27
  288. data/lib/action_controller/templates/scaffolds/new.rhtml +0 -6
  289. data/lib/action_controller/templates/scaffolds/show.rhtml +0 -9
  290. data/lib/action_controller/vendor/xml_node.rb +0 -97
  291. data/lib/action_view/helpers/deprecated_helper.rb +0 -37
  292. data/lib/action_view/helpers/java_script_macros_helper.rb +0 -233
  293. data/lib/action_view/helpers/pagination_helper.rb +0 -86
  294. data/test/activerecord/active_record_assertions_test.rb +0 -92
  295. data/test/activerecord/pagination_test.rb +0 -165
  296. data/test/controller/deprecated_instance_variables_test.rb +0 -48
  297. data/test/controller/raw_post_test.rb +0 -68
  298. data/test/fixtures/deprecated_instance_variables/_cookies_ivar.rhtml +0 -1
  299. data/test/fixtures/deprecated_instance_variables/_cookies_method.rhtml +0 -1
  300. data/test/fixtures/deprecated_instance_variables/_flash_ivar.rhtml +0 -1
  301. data/test/fixtures/deprecated_instance_variables/_flash_method.rhtml +0 -1
  302. data/test/fixtures/deprecated_instance_variables/_headers_ivar.rhtml +0 -1
  303. data/test/fixtures/deprecated_instance_variables/_headers_method.rhtml +0 -1
  304. data/test/fixtures/deprecated_instance_variables/_params_ivar.rhtml +0 -1
  305. data/test/fixtures/deprecated_instance_variables/_params_method.rhtml +0 -1
  306. data/test/fixtures/deprecated_instance_variables/_request_ivar.rhtml +0 -1
  307. data/test/fixtures/deprecated_instance_variables/_request_method.rhtml +0 -1
  308. data/test/fixtures/deprecated_instance_variables/_response_ivar.rhtml +0 -1
  309. data/test/fixtures/deprecated_instance_variables/_response_method.rhtml +0 -1
  310. data/test/fixtures/deprecated_instance_variables/_session_ivar.rhtml +0 -1
  311. data/test/fixtures/deprecated_instance_variables/_session_method.rhtml +0 -1
  312. data/test/fixtures/respond_to/layouts/standard.rhtml +0 -1
  313. data/test/fixtures/test/_hash_object.rhtml +0 -1
  314. data/test/fixtures/test/list.rhtml +0 -1
  315. data/test/template/deprecated_helper_test.rb +0 -36
  316. data/test/template/deprecated_instance_variables_test.rb +0 -43
  317. 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, :new_name_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 = entities
11
- @singular = options[:singular] || plural.to_s.singularize
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
- "#{new_name_prefix}#{singular}_"
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
- @plural = @singular = entity
93
- @options = options
94
- arrange_actions
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. This is
104
- # useful for implementing REST API's, where a single resource has different
105
- # behavior based on the HTTP verb (method) used to access it.
106
- #
107
- # Example:
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
- # map.resources :messages
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
- # messages messages_url, hash_for_messages_url,
195
+ # ============ =====================================================
196
+ # messages messages_url, hash_for_messages_url,
157
197
  # messages_path, hash_for_messages_path
158
- # message message_url(id), hash_for_message_url(id),
198
+ #
199
+ # message message_url(id), hash_for_message_url(id),
159
200
  # message_path(id), hash_for_message_path(id)
160
- # new_message new_message_url, hash_for_new_message_url,
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
- # # becomes
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 various options, too, to customize the resulting
185
- # routes:
186
- # * <tt>:controller</tt> -- specify the controller name for the routes.
187
- # * <tt>:singular</tt> -- specify the singular name used in the member routes.
188
- # * <tt>:path_prefix</tt> -- set a prefix to the routes with required route variables.
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> -- define a prefix for all generated routes, usually ending in an underscore.
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
- # * <tt>:collection</tt> -- add named routes for other actions that operate on the collection.
215
- # Takes a hash of <tt>#{action} => #{method}</tt>, where method is <tt>:get</tt>/<tt>:post</tt>/<tt>:put</tt>/<tt>:delete</tt>
216
- # 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.
217
- # * <tt>:member</tt> -- same as :collection, but for actions that operate on a specific member.
218
- # * <tt>:new</tt> -- same as :collection, but for actions that operate on the new resource action.
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.last.is_a?(Hash) ? entities.pop : { }
251
- entities.each { |entity| map_resource entity, options.dup, &block }
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 the current user visiting the application, such as a user's
256
- # /account profile.
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
- # - A singular name is given to map.resource. The default controller name is taken from the singular name.
260
- # - There is no <tt>:collection</tt> option as there is only the singleton resource.
261
- # - There is no <tt>:singular</tt> option as the singular name is passed to map.resource.
262
- # - No default index route is created for the singleton resource controller.
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
- # Example:
332
+ # For example:
266
333
  #
267
- # map.resource :account
334
+ # map.resource :account
268
335
  #
269
- # class AccountController < ActionController::Base
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 use in
302
- # controllers and views. <tt>map.resource :account</tt> produces the following named routes and helpers:
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
- # account account_url, hash_for_account_url,
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.last.is_a?(Hash) ? entities.pop : { }
311
- entities.each { |entity| map_singleton_resource entity, options.dup, &block }
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, :new_name_prefix => resource.nesting_name_prefix, &block)
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, :new_name_prefix => resource.nesting_name_prefix, &block)
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
- map.named_route("#{resource.name_prefix}#{resource.plural}", resource.path, index_action_options)
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.deprecate_name_prefix?
374
- map.deprecated_named_route("#{resource.name_prefix}#{resource.plural}", "#{resource.plural}")
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.connect("#{resource.member_path};#{action}", action_options)
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 conditions_for(method)
472
- { :conditions => method == :any ? {} : { :method => method } }
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) ? {} : { :requirements => { :id => Regexp.new("[^#{Routing::SEPARATORS.join}]+") } }
514
+ require_id = !resource.kind_of?(SingletonResource)
478
515
  case default_options[:action]
479
- when "index", "new" : default_options.merge(conditions_for(method || :get))
480
- when "create" : default_options.merge(conditions_for(method || :post))
481
- when "show", "edit" : default_options.merge(conditions_for(method || :get)).merge(require_id)
482
- when "update" : default_options.merge(conditions_for(method || :put)).merge(require_id)
483
- when "destroy" : default_options.merge(conditions_for(method || :delete)).merge(require_id)
484
- else default_options.merge(conditions_for(method))
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.send :include, ActionController::Resources
527
+ class ActionController::Routing::RouteSet::Mapper
528
+ include ActionController::Resources
529
+ end