actionpack 3.2.22.5 → 5.2.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionpack might be problematic. Click here for more details.

Files changed (271) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +279 -603
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +13 -297
  5. data/lib/abstract_controller/asset_paths.rb +4 -2
  6. data/lib/abstract_controller/base.rb +82 -52
  7. data/lib/abstract_controller/caching/fragments.rb +166 -0
  8. data/lib/abstract_controller/caching.rb +66 -0
  9. data/lib/abstract_controller/callbacks.rb +117 -103
  10. data/lib/abstract_controller/collector.rb +18 -7
  11. data/lib/abstract_controller/error.rb +6 -0
  12. data/lib/abstract_controller/helpers.rb +65 -38
  13. data/lib/abstract_controller/logger.rb +3 -2
  14. data/lib/abstract_controller/railties/routes_helpers.rb +5 -3
  15. data/lib/abstract_controller/rendering.rb +77 -129
  16. data/lib/abstract_controller/translation.rb +21 -3
  17. data/lib/abstract_controller/url_for.rb +9 -7
  18. data/lib/abstract_controller.rb +12 -13
  19. data/lib/action_controller/api/api_rendering.rb +16 -0
  20. data/lib/action_controller/api.rb +149 -0
  21. data/lib/action_controller/base.rb +81 -40
  22. data/lib/action_controller/caching.rb +22 -62
  23. data/lib/action_controller/form_builder.rb +50 -0
  24. data/lib/action_controller/log_subscriber.rb +30 -18
  25. data/lib/action_controller/metal/basic_implicit_render.rb +13 -0
  26. data/lib/action_controller/metal/conditional_get.rb +190 -47
  27. data/lib/action_controller/metal/content_security_policy.rb +52 -0
  28. data/lib/action_controller/metal/cookies.rb +3 -3
  29. data/lib/action_controller/metal/data_streaming.rb +40 -65
  30. data/lib/action_controller/metal/etag_with_flash.rb +18 -0
  31. data/lib/action_controller/metal/etag_with_template_digest.rb +57 -0
  32. data/lib/action_controller/metal/exceptions.rb +19 -12
  33. data/lib/action_controller/metal/flash.rb +42 -9
  34. data/lib/action_controller/metal/force_ssl.rb +79 -19
  35. data/lib/action_controller/metal/head.rb +35 -10
  36. data/lib/action_controller/metal/helpers.rb +31 -21
  37. data/lib/action_controller/metal/http_authentication.rb +182 -134
  38. data/lib/action_controller/metal/implicit_render.rb +62 -8
  39. data/lib/action_controller/metal/instrumentation.rb +28 -26
  40. data/lib/action_controller/metal/live.rb +312 -0
  41. data/lib/action_controller/metal/mime_responds.rb +159 -163
  42. data/lib/action_controller/metal/parameter_encoding.rb +51 -0
  43. data/lib/action_controller/metal/params_wrapper.rb +146 -93
  44. data/lib/action_controller/metal/redirecting.rb +80 -56
  45. data/lib/action_controller/metal/renderers.rb +119 -47
  46. data/lib/action_controller/metal/rendering.rb +89 -32
  47. data/lib/action_controller/metal/request_forgery_protection.rb +373 -41
  48. data/lib/action_controller/metal/rescue.rb +9 -16
  49. data/lib/action_controller/metal/streaming.rb +39 -45
  50. data/lib/action_controller/metal/strong_parameters.rb +1086 -0
  51. data/lib/action_controller/metal/testing.rb +8 -29
  52. data/lib/action_controller/metal/url_for.rb +43 -32
  53. data/lib/action_controller/metal.rb +112 -106
  54. data/lib/action_controller/railtie.rb +56 -18
  55. data/lib/action_controller/railties/helpers.rb +24 -0
  56. data/lib/action_controller/renderer.rb +117 -0
  57. data/lib/action_controller/template_assertions.rb +11 -0
  58. data/lib/action_controller/test_case.rb +402 -347
  59. data/lib/action_controller.rb +31 -30
  60. data/lib/action_dispatch/http/cache.rb +133 -34
  61. data/lib/action_dispatch/http/content_security_policy.rb +272 -0
  62. data/lib/action_dispatch/http/filter_parameters.rb +40 -24
  63. data/lib/action_dispatch/http/filter_redirect.rb +37 -0
  64. data/lib/action_dispatch/http/headers.rb +117 -16
  65. data/lib/action_dispatch/http/mime_negotiation.rb +98 -33
  66. data/lib/action_dispatch/http/mime_type.rb +198 -146
  67. data/lib/action_dispatch/http/mime_types.rb +22 -7
  68. data/lib/action_dispatch/http/parameter_filter.rb +61 -49
  69. data/lib/action_dispatch/http/parameters.rb +94 -51
  70. data/lib/action_dispatch/http/rack_cache.rb +4 -3
  71. data/lib/action_dispatch/http/request.rb +262 -117
  72. data/lib/action_dispatch/http/response.rb +400 -86
  73. data/lib/action_dispatch/http/upload.rb +66 -29
  74. data/lib/action_dispatch/http/url.rb +232 -60
  75. data/lib/action_dispatch/journey/formatter.rb +189 -0
  76. data/lib/action_dispatch/journey/gtg/builder.rb +164 -0
  77. data/lib/action_dispatch/journey/gtg/simulator.rb +41 -0
  78. data/lib/action_dispatch/journey/gtg/transition_table.rb +158 -0
  79. data/lib/action_dispatch/journey/nfa/builder.rb +78 -0
  80. data/lib/action_dispatch/journey/nfa/dot.rb +36 -0
  81. data/lib/action_dispatch/journey/nfa/simulator.rb +49 -0
  82. data/lib/action_dispatch/journey/nfa/transition_table.rb +120 -0
  83. data/lib/action_dispatch/journey/nodes/node.rb +140 -0
  84. data/lib/action_dispatch/journey/parser.rb +199 -0
  85. data/lib/action_dispatch/journey/parser.y +50 -0
  86. data/lib/action_dispatch/journey/parser_extras.rb +31 -0
  87. data/lib/action_dispatch/journey/path/pattern.rb +199 -0
  88. data/lib/action_dispatch/journey/route.rb +203 -0
  89. data/lib/action_dispatch/journey/router/utils.rb +102 -0
  90. data/lib/action_dispatch/journey/router.rb +156 -0
  91. data/lib/action_dispatch/journey/routes.rb +82 -0
  92. data/lib/action_dispatch/journey/scanner.rb +64 -0
  93. data/lib/action_dispatch/journey/visitors.rb +268 -0
  94. data/lib/action_dispatch/journey/visualizer/fsm.css +30 -0
  95. data/lib/action_dispatch/journey/visualizer/fsm.js +134 -0
  96. data/lib/action_dispatch/journey/visualizer/index.html.erb +52 -0
  97. data/lib/action_dispatch/journey.rb +7 -0
  98. data/lib/action_dispatch/middleware/callbacks.rb +17 -13
  99. data/lib/action_dispatch/middleware/cookies.rb +494 -162
  100. data/lib/action_dispatch/middleware/debug_exceptions.rb +176 -53
  101. data/lib/action_dispatch/middleware/debug_locks.rb +124 -0
  102. data/lib/action_dispatch/middleware/exception_wrapper.rb +103 -38
  103. data/lib/action_dispatch/middleware/executor.rb +21 -0
  104. data/lib/action_dispatch/middleware/flash.rb +128 -91
  105. data/lib/action_dispatch/middleware/public_exceptions.rb +43 -16
  106. data/lib/action_dispatch/middleware/reloader.rb +6 -83
  107. data/lib/action_dispatch/middleware/remote_ip.rb +151 -49
  108. data/lib/action_dispatch/middleware/request_id.rb +19 -15
  109. data/lib/action_dispatch/middleware/session/abstract_store.rb +38 -34
  110. data/lib/action_dispatch/middleware/session/cache_store.rb +14 -9
  111. data/lib/action_dispatch/middleware/session/cookie_store.rb +94 -44
  112. data/lib/action_dispatch/middleware/session/mem_cache_store.rb +15 -4
  113. data/lib/action_dispatch/middleware/show_exceptions.rb +36 -61
  114. data/lib/action_dispatch/middleware/ssl.rb +150 -0
  115. data/lib/action_dispatch/middleware/stack.rb +33 -41
  116. data/lib/action_dispatch/middleware/static.rb +92 -48
  117. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +22 -0
  118. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +23 -0
  119. data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +27 -0
  120. data/lib/action_dispatch/middleware/templates/rescues/_source.text.erb +8 -0
  121. data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +52 -0
  122. data/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +9 -0
  123. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +16 -0
  124. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +9 -0
  125. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +21 -0
  126. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb +13 -0
  127. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +134 -5
  128. data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +11 -0
  129. data/lib/action_dispatch/middleware/templates/rescues/missing_template.text.erb +3 -0
  130. data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +32 -0
  131. data/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb +11 -0
  132. data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +20 -0
  133. data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +7 -0
  134. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +6 -0
  135. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +3 -0
  136. data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +16 -0
  137. data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +200 -0
  138. data/lib/action_dispatch/railtie.rb +29 -8
  139. data/lib/action_dispatch/request/session.rb +234 -0
  140. data/lib/action_dispatch/request/utils.rb +78 -0
  141. data/lib/action_dispatch/routing/endpoint.rb +17 -0
  142. data/lib/action_dispatch/routing/inspector.rb +225 -0
  143. data/lib/action_dispatch/routing/mapper.rb +1329 -582
  144. data/lib/action_dispatch/routing/polymorphic_routes.rb +237 -94
  145. data/lib/action_dispatch/routing/redirection.rb +120 -50
  146. data/lib/action_dispatch/routing/route_set.rb +545 -322
  147. data/lib/action_dispatch/routing/routes_proxy.rb +37 -7
  148. data/lib/action_dispatch/routing/url_for.rb +103 -34
  149. data/lib/action_dispatch/routing.rb +66 -99
  150. data/lib/action_dispatch/system_test_case.rb +147 -0
  151. data/lib/action_dispatch/system_testing/browser.rb +49 -0
  152. data/lib/action_dispatch/system_testing/driver.rb +59 -0
  153. data/lib/action_dispatch/system_testing/server.rb +31 -0
  154. data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +96 -0
  155. data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +31 -0
  156. data/lib/action_dispatch/system_testing/test_helpers/undef_methods.rb +26 -0
  157. data/lib/action_dispatch/testing/assertion_response.rb +47 -0
  158. data/lib/action_dispatch/testing/assertions/response.rb +53 -42
  159. data/lib/action_dispatch/testing/assertions/routing.rb +79 -74
  160. data/lib/action_dispatch/testing/assertions.rb +15 -9
  161. data/lib/action_dispatch/testing/integration.rb +361 -207
  162. data/lib/action_dispatch/testing/request_encoder.rb +55 -0
  163. data/lib/action_dispatch/testing/test_process.rb +28 -19
  164. data/lib/action_dispatch/testing/test_request.rb +30 -33
  165. data/lib/action_dispatch/testing/test_response.rb +35 -11
  166. data/lib/action_dispatch.rb +42 -32
  167. data/lib/action_pack/gem_version.rb +17 -0
  168. data/lib/action_pack/version.rb +7 -7
  169. data/lib/action_pack.rb +4 -2
  170. metadata +116 -175
  171. data/lib/abstract_controller/layouts.rb +0 -423
  172. data/lib/abstract_controller/view_paths.rb +0 -96
  173. data/lib/action_controller/caching/actions.rb +0 -185
  174. data/lib/action_controller/caching/fragments.rb +0 -127
  175. data/lib/action_controller/caching/pages.rb +0 -187
  176. data/lib/action_controller/caching/sweeping.rb +0 -97
  177. data/lib/action_controller/deprecated/integration_test.rb +0 -2
  178. data/lib/action_controller/deprecated/performance_test.rb +0 -1
  179. data/lib/action_controller/deprecated.rb +0 -3
  180. data/lib/action_controller/metal/compatibility.rb +0 -65
  181. data/lib/action_controller/metal/hide_actions.rb +0 -41
  182. data/lib/action_controller/metal/rack_delegation.rb +0 -26
  183. data/lib/action_controller/metal/responder.rb +0 -286
  184. data/lib/action_controller/metal/session_management.rb +0 -14
  185. data/lib/action_controller/middleware.rb +0 -39
  186. data/lib/action_controller/railties/paths.rb +0 -25
  187. data/lib/action_controller/record_identifier.rb +0 -85
  188. data/lib/action_controller/vendor/html-scanner/html/document.rb +0 -68
  189. data/lib/action_controller/vendor/html-scanner/html/node.rb +0 -532
  190. data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +0 -177
  191. data/lib/action_controller/vendor/html-scanner/html/selector.rb +0 -830
  192. data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +0 -107
  193. data/lib/action_controller/vendor/html-scanner/html/version.rb +0 -11
  194. data/lib/action_controller/vendor/html-scanner.rb +0 -20
  195. data/lib/action_dispatch/middleware/best_standards_support.rb +0 -30
  196. data/lib/action_dispatch/middleware/body_proxy.rb +0 -30
  197. data/lib/action_dispatch/middleware/head.rb +0 -18
  198. data/lib/action_dispatch/middleware/params_parser.rb +0 -75
  199. data/lib/action_dispatch/middleware/rescue.rb +0 -26
  200. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb +0 -31
  201. data/lib/action_dispatch/middleware/templates/rescues/_trace.erb +0 -26
  202. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb +0 -10
  203. data/lib/action_dispatch/middleware/templates/rescues/missing_template.erb +0 -2
  204. data/lib/action_dispatch/middleware/templates/rescues/routing_error.erb +0 -15
  205. data/lib/action_dispatch/middleware/templates/rescues/template_error.erb +0 -17
  206. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb +0 -2
  207. data/lib/action_dispatch/testing/assertions/dom.rb +0 -37
  208. data/lib/action_dispatch/testing/assertions/selector.rb +0 -435
  209. data/lib/action_dispatch/testing/assertions/tag.rb +0 -138
  210. data/lib/action_dispatch/testing/performance_test.rb +0 -10
  211. data/lib/action_view/asset_paths.rb +0 -142
  212. data/lib/action_view/base.rb +0 -220
  213. data/lib/action_view/buffers.rb +0 -43
  214. data/lib/action_view/context.rb +0 -36
  215. data/lib/action_view/flows.rb +0 -79
  216. data/lib/action_view/helpers/active_model_helper.rb +0 -50
  217. data/lib/action_view/helpers/asset_paths.rb +0 -7
  218. data/lib/action_view/helpers/asset_tag_helper.rb +0 -457
  219. data/lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb +0 -146
  220. data/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb +0 -93
  221. data/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +0 -193
  222. data/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +0 -148
  223. data/lib/action_view/helpers/atom_feed_helper.rb +0 -200
  224. data/lib/action_view/helpers/cache_helper.rb +0 -64
  225. data/lib/action_view/helpers/capture_helper.rb +0 -203
  226. data/lib/action_view/helpers/controller_helper.rb +0 -25
  227. data/lib/action_view/helpers/csrf_helper.rb +0 -32
  228. data/lib/action_view/helpers/date_helper.rb +0 -1062
  229. data/lib/action_view/helpers/debug_helper.rb +0 -40
  230. data/lib/action_view/helpers/form_helper.rb +0 -1486
  231. data/lib/action_view/helpers/form_options_helper.rb +0 -658
  232. data/lib/action_view/helpers/form_tag_helper.rb +0 -685
  233. data/lib/action_view/helpers/javascript_helper.rb +0 -110
  234. data/lib/action_view/helpers/number_helper.rb +0 -622
  235. data/lib/action_view/helpers/output_safety_helper.rb +0 -38
  236. data/lib/action_view/helpers/record_tag_helper.rb +0 -111
  237. data/lib/action_view/helpers/rendering_helper.rb +0 -92
  238. data/lib/action_view/helpers/sanitize_helper.rb +0 -259
  239. data/lib/action_view/helpers/tag_helper.rb +0 -167
  240. data/lib/action_view/helpers/text_helper.rb +0 -426
  241. data/lib/action_view/helpers/translation_helper.rb +0 -91
  242. data/lib/action_view/helpers/url_helper.rb +0 -693
  243. data/lib/action_view/helpers.rb +0 -60
  244. data/lib/action_view/locale/en.yml +0 -160
  245. data/lib/action_view/log_subscriber.rb +0 -28
  246. data/lib/action_view/lookup_context.rb +0 -258
  247. data/lib/action_view/path_set.rb +0 -101
  248. data/lib/action_view/railtie.rb +0 -55
  249. data/lib/action_view/renderer/abstract_renderer.rb +0 -41
  250. data/lib/action_view/renderer/partial_renderer.rb +0 -415
  251. data/lib/action_view/renderer/renderer.rb +0 -61
  252. data/lib/action_view/renderer/streaming_template_renderer.rb +0 -106
  253. data/lib/action_view/renderer/template_renderer.rb +0 -95
  254. data/lib/action_view/template/error.rb +0 -128
  255. data/lib/action_view/template/handlers/builder.rb +0 -26
  256. data/lib/action_view/template/handlers/erb.rb +0 -125
  257. data/lib/action_view/template/handlers.rb +0 -50
  258. data/lib/action_view/template/resolver.rb +0 -298
  259. data/lib/action_view/template/text.rb +0 -30
  260. data/lib/action_view/template.rb +0 -337
  261. data/lib/action_view/test_case.rb +0 -246
  262. data/lib/action_view/testing/resolvers.rb +0 -49
  263. data/lib/action_view.rb +0 -84
  264. data/lib/sprockets/assets.rake +0 -99
  265. data/lib/sprockets/bootstrap.rb +0 -37
  266. data/lib/sprockets/compressors.rb +0 -83
  267. data/lib/sprockets/helpers/isolated_helper.rb +0 -13
  268. data/lib/sprockets/helpers/rails_helper.rb +0 -182
  269. data/lib/sprockets/helpers.rb +0 -6
  270. data/lib/sprockets/railtie.rb +0 -62
  271. data/lib/sprockets/static_compiler.rb +0 -56
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2004-2011 David Heinemeier Hansson
1
+ Copyright (c) 2004-2018 David Heinemeier Hansson
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -10,332 +10,48 @@ It consists of several modules:
10
10
 
11
11
  * Action Dispatch, which parses information about the web request, handles
12
12
  routing as defined by the user, and does advanced processing related to HTTP
13
- such as MIME-type negotiation, decoding parameters in POST/PUT bodies,
13
+ such as MIME-type negotiation, decoding parameters in POST, PATCH, or PUT bodies,
14
14
  handling HTTP caching logic, cookies and sessions.
15
15
 
16
16
  * Action Controller, which provides a base controller class that can be
17
17
  subclassed to implement filters and actions to handle requests. The result
18
18
  of an action is typically content generated from views.
19
19
 
20
- * Action View, which handles view template lookup and rendering, and provides
21
- view helpers that assist when building HTML forms, Atom feeds and more.
22
- Template formats that Action View handles are ERB (embedded Ruby, typically
23
- used to inline short Ruby snippets inside HTML), and XML Builder.
24
-
25
20
  With the Ruby on Rails framework, users only directly interface with the
26
21
  Action Controller module. Necessary Action Dispatch functionality is activated
27
22
  by default and Action View rendering is implicitly triggered by Action
28
23
  Controller. However, these modules are designed to function on their own and
29
24
  can be used outside of Rails.
30
25
 
31
- A short rundown of some of the major features:
32
-
33
- * Actions grouped in controller as methods instead of separate command objects
34
- and can therefore share helper methods
35
-
36
- class CustomersController < ActionController::Base
37
- def show
38
- @customer = find_customer
39
- end
40
-
41
- def update
42
- @customer = find_customer
43
- if @customer.update_attributes(params[:customer])
44
- redirect_to :action => "show"
45
- else
46
- render :action => "edit"
47
- end
48
- end
49
-
50
- private
51
- def find_customer
52
- Customer.find params[:id]
53
- end
54
- end
55
-
56
- {Learn more}[link:classes/ActionController/Base.html]
57
-
58
-
59
- * ERB templates (static content mixed with dynamic output from ruby)
60
-
61
- <% @posts.each do |post| %>
62
- Title: <%= post.title %>
63
- <% end %>
64
-
65
- All post titles: <%= @posts.collect{ |p| p.title }.join(", ") %>
66
-
67
- <% unless @person.is_client? %>
68
- Not for clients to see...
69
- <% end %>
70
-
71
- {Learn more}[link:classes/ActionView.html]
72
-
73
-
74
- * "Builder" templates (great for XML content, like RSS)
75
-
76
- xml.rss("version" => "2.0") do
77
- xml.channel do
78
- xml.title(@feed_title)
79
- xml.link(@url)
80
- xml.description "Basecamp: Recent items"
81
- xml.language "en-us"
82
- xml.ttl "40"
83
-
84
- @recent_items.each do |item|
85
- xml.item do
86
- xml.title(item_title(item))
87
- xml.description(item_description(item))
88
- xml.pubDate(item_pubDate(item))
89
- xml.guid(@recent_items.url(item))
90
- xml.link(@recent_items.url(item))
91
- end
92
- end
93
- end
94
- end
95
-
96
- {Learn more}[link:classes/ActionView/Base.html]
97
-
98
-
99
- * Filters for pre- and post-processing of the response
100
-
101
- class WeblogController < ActionController::Base
102
- # filters as methods
103
- before_filter :authenticate, :cache, :audit
104
-
105
- # filter as a proc
106
- after_filter { |c| c.response.body = Gzip::compress(c.response.body) }
107
-
108
- # class filter
109
- after_filter LocalizeFilter
110
-
111
- def index
112
- # Before this action is run, the user will be authenticated, the cache
113
- # will be examined to see if a valid copy of the results already
114
- # exists, and the action will be logged for auditing.
115
-
116
- # After this action has run, the output will first be localized then
117
- # compressed to minimize bandwidth usage
118
- end
119
-
120
- private
121
- def authenticate
122
- # Implement the filter with full access to both request and response
123
- end
124
- end
125
-
126
- {Learn more}[link:classes/ActionController/Filters/ClassMethods.html]
127
-
128
-
129
- * Helpers for forms, dates, action links, and text
130
-
131
- <%= text_field_tag "post", "title", "size" => 30 %>
132
- <%= link_to "New post", :controller => "post", :action => "new" %>
133
- <%= truncate(post.title, :length => 25) %>
134
-
135
- {Learn more}[link:classes/ActionView/Helpers.html]
136
-
137
-
138
- * Layout sharing for template reuse
139
-
140
- class WeblogController < ActionController::Base
141
- layout "weblog_layout"
142
-
143
- def hello_world
144
- end
145
- end
146
-
147
- Layout file (called weblog_layout):
148
- <html><body><%= yield %></body></html>
149
-
150
- Template for hello_world action:
151
- <h1>Hello world</h1>
152
-
153
- Result of running hello_world action:
154
- <html><body><h1>Hello world</h1></body></html>
155
-
156
- {Learn more}[link:classes/ActionController/Layout/ClassMethods.html]
157
-
158
-
159
- * Routing makes pretty URLs incredibly easy
160
-
161
- match 'clients/:client_name/:project_name/:controller/:action'
162
-
163
- Accessing "/clients/37signals/basecamp/project/index" calls ProjectController#index with
164
- { "client_name" => "37signals", "project_name" => "basecamp" } in `params`
165
-
166
- From that action, you can write the redirect in a number of ways:
167
-
168
- redirect_to(:action => "edit") =>
169
- /clients/37signals/basecamp/project/edit
170
-
171
- redirect_to(:client_name => "nextangle", :project_name => "rails") =>
172
- /clients/nextangle/rails/project/index
173
-
174
- {Learn more}[link:classes/ActionDispatch/Routing.html]
175
-
176
-
177
- * Easy testing of both controller and rendered template through ActionController::TestCase
178
-
179
- class LoginControllerTest < ActionController::TestCase
180
- def test_failing_authenticate
181
- process :authenticate, :user_name => "nop", :password => ""
182
- assert flash.has_key?(:alert)
183
- assert_redirected_to :action => "index"
184
- end
185
- end
186
-
187
- {Learn more}[link:classes/ActionController/TestCase.html]
188
-
189
-
190
- * Automated benchmarking and integrated logging
191
-
192
- Started GET "/weblog" for 127.0.0.1 at Fri May 28 00:41:55
193
- Processing by WeblogController#index as HTML
194
- Rendered weblog/index.html.erb within layouts/application (25.7ms)
195
- Completed 200 OK in 29.3ms
196
-
197
- If Active Record is used as the model, you'll have the database debugging
198
- as well:
199
-
200
- Started POST "/posts" for 127.0.0.1 at Sat Jun 19 14:04:23
201
- Processing by PostsController#create as HTML
202
- Parameters: {"post"=>{"title"=>"this is good"}}
203
- SQL (0.6ms) INSERT INTO posts (title) VALUES('this is good')
204
- Redirected to http://example.com/posts/5
205
- Completed 302 Found in 221ms (Views: 215ms | ActiveRecord: 0.6ms)
206
-
207
- You specify a logger through a class method, such as:
208
-
209
- ActionController::Base.logger = Logger.new("Application Log")
210
- ActionController::Base.logger = Log4r::Logger.new("Application Log")
211
-
212
-
213
- * Caching at three levels of granularity (page, action, fragment)
214
-
215
- class WeblogController < ActionController::Base
216
- caches_page :show
217
- caches_action :account
218
-
219
- def show
220
- # the output of the method will be cached as
221
- # ActionController::Base.page_cache_directory + "/weblog/show.html"
222
- # and the web server will pick it up without even hitting Rails
223
- end
224
-
225
- def account
226
- # the output of the method will be cached in the fragment store
227
- # but Rails is hit to retrieve it, so filters are run
228
- end
229
-
230
- def update
231
- List.update(params[:list][:id], params[:list])
232
- expire_page :action => "show", :id => params[:list][:id]
233
- expire_action :action => "account"
234
- redirect_to :action => "show", :id => params[:list][:id]
235
- end
236
- end
237
-
238
- {Learn more}[link:classes/ActionController/Caching.html]
239
-
240
-
241
- * Powerful debugging mechanism for local requests
242
-
243
- All exceptions raised on actions performed on the request of a local user
244
- will be presented with a tailored debugging screen that includes exception
245
- message, stack trace, request parameters, session contents, and the
246
- half-finished response.
247
-
248
- {Learn more}[link:classes/ActionController/Rescue.html]
249
-
250
-
251
- == Simple example (from outside of Rails)
252
-
253
- This example will implement a simple weblog system using inline templates and
254
- an Active Record model. So let's build that WeblogController with just a few
255
- methods:
256
-
257
- require 'action_controller'
258
- require 'post'
259
-
260
- class WeblogController < ActionController::Base
261
- layout "weblog/layout"
262
-
263
- def index
264
- @posts = Post.all
265
- end
266
-
267
- def show
268
- @post = Post.find(params[:id])
269
- end
270
-
271
- def new
272
- @post = Post.new
273
- end
274
-
275
- def create
276
- @post = Post.create(params[:post])
277
- redirect_to :action => "show", :id => @post.id
278
- end
279
- end
280
-
281
- WeblogController::Base.view_paths = [ File.dirname(__FILE__) ]
282
- WeblogController.process_cgi if $0 == __FILE__
283
-
284
- The last two lines are responsible for telling ActionController where the
285
- template files are located and actually running the controller on a new
286
- request from the web-server (e.g., Apache).
287
-
288
- And the templates look like this:
289
-
290
- weblog/layout.html.erb:
291
- <html><body>
292
- <%= yield %>
293
- </body></html>
294
-
295
- weblog/index.html.erb:
296
- <% @posts.each do |post| %>
297
- <p><%= link_to(post.title, :action => "show", :id => post.id) %></p>
298
- <% end %>
299
-
300
- weblog/show.html.erb:
301
- <p>
302
- <b><%= @post.title %></b><br/>
303
- <b><%= @post.content %></b>
304
- </p>
305
-
306
- weblog/new.html.erb:
307
- <%= form "post" %>
308
-
309
- This simple setup will list all the posts in the system on the index page,
310
- which is called by accessing /weblog/. It uses the form builder for the Active
311
- Record model to make the new screen, which in turn hands everything over to
312
- the create action (that's the default target for the form builder when given a
313
- new model). After creating the post, it'll redirect to the show page using
314
- an URL such as /weblog/5 (where 5 is the id of the post).
315
-
316
26
 
317
27
  == Download and installation
318
28
 
319
29
  The latest version of Action Pack can be installed with RubyGems:
320
30
 
321
- % [sudo] gem install actionpack
31
+ $ gem install actionpack
322
32
 
323
- Source code can be downloaded as part of the Rails project on GitHub
33
+ Source code can be downloaded as part of the Rails project on GitHub:
324
34
 
325
- * https://github.com/rails/rails/tree/3-2-stable/actionpack
35
+ * https://github.com/rails/rails/tree/5-2-stable/actionpack
326
36
 
327
37
 
328
38
  == License
329
39
 
330
- Action Pack is released under the MIT license.
40
+ Action Pack is released under the MIT license:
41
+
42
+ * https://opensource.org/licenses/MIT
331
43
 
332
44
 
333
45
  == Support
334
46
 
335
- API documentation is at
47
+ API documentation is at:
336
48
 
337
49
  * http://api.rubyonrails.org
338
50
 
339
- Bug reports and feature requests can be filed with the rest for the Ruby on Rails project here:
51
+ Bug reports for the Ruby on Rails project can be filed here:
340
52
 
341
53
  * https://github.com/rails/rails/issues
54
+
55
+ Feature requests should be discussed on the rails-core mailing list here:
56
+
57
+ * https://groups.google.com/forum/?fromgroups#!forum/rubyonrails-core
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AbstractController
2
- module AssetPaths
4
+ module AssetPaths #:nodoc:
3
5
  extend ActiveSupport::Concern
4
6
 
5
7
  included do
6
- config_accessor :asset_host, :asset_path, :assets_dir, :javascripts_dir,
8
+ config_accessor :asset_host, :assets_dir, :javascripts_dir,
7
9
  :stylesheets_dir, :default_asset_host_protocol, :relative_url_root
8
10
  end
9
11
  end
@@ -1,25 +1,36 @@
1
- require 'erubis'
2
- require 'active_support/configurable'
3
- require 'active_support/descendants_tracker'
4
- require 'active_support/core_ext/module/anonymous'
1
+ # frozen_string_literal: true
2
+
3
+ require "abstract_controller/error"
4
+ require "active_support/configurable"
5
+ require "active_support/descendants_tracker"
6
+ require "active_support/core_ext/module/anonymous"
7
+ require "active_support/core_ext/module/attr_internal"
5
8
 
6
9
  module AbstractController
7
- class Error < StandardError; end
8
- class ActionNotFound < StandardError; end
10
+ # Raised when a non-existing controller action is triggered.
11
+ class ActionNotFound < StandardError
12
+ end
9
13
 
10
- # <tt>AbstractController::Base</tt> is a low-level API. Nobody should be
14
+ # AbstractController::Base is a low-level API. Nobody should be
11
15
  # using it directly, and subclasses (like ActionController::Base) are
12
16
  # expected to provide their own +render+ method, since rendering means
13
17
  # different things depending on the context.
14
18
  class Base
19
+ ##
20
+ # Returns the body of the HTTP response sent by the controller.
15
21
  attr_internal :response_body
22
+
23
+ ##
24
+ # Returns the name of the action this controller is processing.
16
25
  attr_internal :action_name
26
+
27
+ ##
28
+ # Returns the formats that can be processed by the controller.
17
29
  attr_internal :formats
18
30
 
19
31
  include ActiveSupport::Configurable
20
32
  extend ActiveSupport::DescendantsTracker
21
33
 
22
- undef_method :not_implemented
23
34
  class << self
24
35
  attr_reader :abstract
25
36
  alias_method :abstract?, :abstract
@@ -30,36 +41,36 @@ module AbstractController
30
41
  @abstract = true
31
42
  end
32
43
 
44
+ def inherited(klass) # :nodoc:
45
+ # Define the abstract ivar on subclasses so that we don't get
46
+ # uninitialized ivar warnings
47
+ unless klass.instance_variable_defined?(:@abstract)
48
+ klass.instance_variable_set(:@abstract, false)
49
+ end
50
+ super
51
+ end
52
+
33
53
  # A list of all internal methods for a controller. This finds the first
34
54
  # abstract superclass of a controller, and gets a list of all public
35
55
  # instance methods on that abstract class. Public instance methods of
36
56
  # a controller would normally be considered action methods, so methods
37
57
  # declared on abstract classes are being removed.
38
- # (ActionController::Metal and ActionController::Base are defined as abstract)
58
+ # (<tt>ActionController::Metal</tt> and ActionController::Base are defined as abstract)
39
59
  def internal_methods
40
60
  controller = self
61
+
41
62
  controller = controller.superclass until controller.abstract?
42
63
  controller.public_instance_methods(true)
43
64
  end
44
65
 
45
- # The list of hidden actions to an empty array. Defaults to an
46
- # empty array. This can be modified by other modules or subclasses
47
- # to specify particular actions as hidden.
48
- #
49
- # ==== Returns
50
- # * <tt>array</tt> - An array of method names that should not be considered actions.
51
- def hidden_actions
52
- []
53
- end
54
-
55
66
  # A list of method names that should be considered actions. This
56
67
  # includes all public instance methods on a controller, less
57
- # any internal methods (see #internal_methods), adding back in
68
+ # any internal methods (see internal_methods), adding back in
58
69
  # any methods that are internal, but still exist on the class
59
- # itself. Finally, #hidden_actions are removed.
70
+ # itself.
60
71
  #
61
72
  # ==== Returns
62
- # * <tt>array</tt> - A list of all methods that should be considered actions.
73
+ # * <tt>Set</tt> - A set of all methods that should be considered actions.
63
74
  def action_methods
64
75
  @action_methods ||= begin
65
76
  # All public instance methods of this class, including ancestors
@@ -67,32 +78,34 @@ module AbstractController
67
78
  # Except for public instance methods of Base and its ancestors
68
79
  internal_methods +
69
80
  # Be sure to include shadowed public instance methods of this class
70
- public_instance_methods(false)).uniq.map { |x| x.to_s } -
71
- # And always exclude explicitly hidden actions
72
- hidden_actions.to_a
81
+ public_instance_methods(false)).uniq.map(&:to_s)
73
82
 
74
- # Clear out AS callback method pollution
75
- methods.reject { |method| method =~ /_one_time_conditions/ }
83
+ methods.to_set
76
84
  end
77
85
  end
78
86
 
79
- # action_methods are cached and there is sometimes need to refresh
80
- # them. clear_action_methods! allows you to do that, so next time
81
- # you run action_methods, they will be recalculated
87
+ # action_methods are cached and there is sometimes a need to refresh
88
+ # them. ::clear_action_methods! allows you to do that, so next time
89
+ # you run action_methods, they will be recalculated.
82
90
  def clear_action_methods!
83
91
  @action_methods = nil
84
92
  end
85
93
 
86
94
  # Returns the full controller name, underscored, without the ending Controller.
87
- # For instance, MyApp::MyPostsController would return "my_app/my_posts" for
88
- # controller_name.
95
+ #
96
+ # class MyApp::MyPostsController < AbstractController::Base
97
+ #
98
+ # end
99
+ #
100
+ # MyApp::MyPostsController.controller_path # => "my_app/my_posts"
89
101
  #
90
102
  # ==== Returns
91
- # * <tt>string</tt>
103
+ # * <tt>String</tt>
92
104
  def controller_path
93
- @controller_path ||= name.sub(/Controller$/, '').underscore unless anonymous?
105
+ @controller_path ||= name.sub(/Controller$/, "".freeze).underscore unless anonymous?
94
106
  end
95
107
 
108
+ # Refresh the cached action_methods when a new action_method is added.
96
109
  def method_added(name)
97
110
  super
98
111
  clear_action_methods!
@@ -105,14 +118,14 @@ module AbstractController
105
118
  #
106
119
  # The actual method that is called is determined by calling
107
120
  # #method_for_action. If no method can handle the action, then an
108
- # ActionNotFound error is raised.
121
+ # AbstractController::ActionNotFound error is raised.
109
122
  #
110
123
  # ==== Returns
111
124
  # * <tt>self</tt>
112
125
  def process(action, *args)
113
- @_action_name = action_name = action.to_s
126
+ @_action_name = action.to_s
114
127
 
115
- unless action_name = _find_action_name(action_name)
128
+ unless action_name = _find_action_name(@_action_name)
116
129
  raise ActionNotFound, "The action '#{action}' could not be found for #{self.class.name}"
117
130
  end
118
131
 
@@ -121,11 +134,12 @@ module AbstractController
121
134
  process_action(action_name, *args)
122
135
  end
123
136
 
124
- # Delegates to the class' #controller_path
137
+ # Delegates to the class' ::controller_path
125
138
  def controller_path
126
139
  self.class.controller_path
127
140
  end
128
141
 
142
+ # Delegates to the class' ::action_methods
129
143
  def action_methods
130
144
  self.class.action_methods
131
145
  end
@@ -135,10 +149,28 @@ module AbstractController
135
149
  #
136
150
  # Notice that <tt>action_methods.include?("foo")</tt> may return
137
151
  # false and <tt>available_action?("foo")</tt> returns true because
138
- # available action consider actions that are also available
152
+ # this method considers actions that are also available
139
153
  # through other means, for example, implicit render ones.
154
+ #
155
+ # ==== Parameters
156
+ # * <tt>action_name</tt> - The name of an action to be tested
140
157
  def available_action?(action_name)
141
- _find_action_name(action_name).present?
158
+ _find_action_name(action_name)
159
+ end
160
+
161
+ # Tests if a response body is set. Used to determine if the
162
+ # +process_action+ callback needs to be terminated in
163
+ # +AbstractController::Callbacks+.
164
+ def performed?
165
+ response_body
166
+ end
167
+
168
+ # Returns true if the given controller is capable of rendering
169
+ # a path. A subclass of +AbstractController::Base+
170
+ # may return false. An Email controller for example does not
171
+ # support paths, only full URLs.
172
+ def self.supports_path?
173
+ true
142
174
  end
143
175
 
144
176
  private
@@ -148,11 +180,6 @@ module AbstractController
148
180
  #
149
181
  # ==== Parameters
150
182
  # * <tt>name</tt> - The name of an action to be tested
151
- #
152
- # ==== Returns
153
- # * <tt>TrueClass</tt>, <tt>FalseClass</tt>
154
- #
155
- # :api: private
156
183
  def action_method?(name)
157
184
  self.class.action_methods.include?(name)
158
185
  end
@@ -193,7 +220,8 @@ module AbstractController
193
220
  #
194
221
  # ==== Returns
195
222
  # * <tt>string</tt> - The name of the method that handles the action
196
- # * false - No valid method name could be found. Raise ActionNotFound.
223
+ # * false - No valid method name could be found.
224
+ # Raise +AbstractController::ActionNotFound+.
197
225
  def _find_action_name(action_name)
198
226
  _valid_action_name?(action_name) && method_for_action(action_name)
199
227
  end
@@ -209,11 +237,11 @@ module AbstractController
209
237
  # with a template matching the action name is considered to exist.
210
238
  #
211
239
  # If you override this method to handle additional cases, you may
212
- # also provide a method (like _handle_method_missing) to handle
240
+ # also provide a method (like +_handle_method_missing+) to handle
213
241
  # the case.
214
242
  #
215
- # If none of these conditions are true, and method_for_action
216
- # returns nil, an ActionNotFound exception will be raised.
243
+ # If none of these conditions are true, and +method_for_action+
244
+ # returns +nil+, an +AbstractController::ActionNotFound+ exception will be raised.
217
245
  #
218
246
  # ==== Parameters
219
247
  # * <tt>action_name</tt> - An action name to find a method name for
@@ -222,14 +250,16 @@ module AbstractController
222
250
  # * <tt>string</tt> - The name of the method that handles the action
223
251
  # * <tt>nil</tt> - No method name could be found.
224
252
  def method_for_action(action_name)
225
- if action_method?(action_name) then action_name
226
- elsif respond_to?(:action_missing, true) then "_handle_action_missing"
253
+ if action_method?(action_name)
254
+ action_name
255
+ elsif respond_to?(:action_missing, true)
256
+ "_handle_action_missing"
227
257
  end
228
258
  end
229
259
 
230
260
  # Checks if the action name is valid and returns false otherwise.
231
261
  def _valid_action_name?(action_name)
232
- action_name.to_s !~ Regexp.new(File::SEPARATOR)
262
+ !action_name.to_s.include? File::SEPARATOR
233
263
  end
234
264
  end
235
265
  end