actionpack 3.2.19 → 4.2.11.3

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 (244) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +412 -503
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +11 -294
  5. data/lib/abstract_controller/asset_paths.rb +2 -2
  6. data/lib/abstract_controller/base.rb +52 -18
  7. data/lib/abstract_controller/callbacks.rb +87 -89
  8. data/lib/abstract_controller/collector.rb +17 -3
  9. data/lib/abstract_controller/helpers.rb +41 -14
  10. data/lib/abstract_controller/logger.rb +1 -2
  11. data/lib/abstract_controller/railties/routes_helpers.rb +3 -3
  12. data/lib/abstract_controller/rendering.rb +65 -118
  13. data/lib/abstract_controller/translation.rb +16 -1
  14. data/lib/abstract_controller/url_for.rb +7 -7
  15. data/lib/abstract_controller.rb +2 -10
  16. data/lib/action_controller/base.rb +61 -28
  17. data/lib/action_controller/caching/fragments.rb +30 -54
  18. data/lib/action_controller/caching.rb +38 -35
  19. data/lib/action_controller/log_subscriber.rb +35 -18
  20. data/lib/action_controller/metal/conditional_get.rb +103 -34
  21. data/lib/action_controller/metal/data_streaming.rb +20 -26
  22. data/lib/action_controller/metal/etag_with_template_digest.rb +50 -0
  23. data/lib/action_controller/metal/exceptions.rb +19 -6
  24. data/lib/action_controller/metal/flash.rb +41 -9
  25. data/lib/action_controller/metal/force_ssl.rb +70 -12
  26. data/lib/action_controller/metal/head.rb +30 -7
  27. data/lib/action_controller/metal/helpers.rb +11 -11
  28. data/lib/action_controller/metal/hide_actions.rb +0 -1
  29. data/lib/action_controller/metal/http_authentication.rb +140 -94
  30. data/lib/action_controller/metal/implicit_render.rb +1 -1
  31. data/lib/action_controller/metal/instrumentation.rb +11 -7
  32. data/lib/action_controller/metal/live.rb +328 -0
  33. data/lib/action_controller/metal/mime_responds.rb +161 -152
  34. data/lib/action_controller/metal/params_wrapper.rb +126 -81
  35. data/lib/action_controller/metal/rack_delegation.rb +10 -4
  36. data/lib/action_controller/metal/redirecting.rb +44 -41
  37. data/lib/action_controller/metal/renderers.rb +48 -19
  38. data/lib/action_controller/metal/rendering.rb +46 -11
  39. data/lib/action_controller/metal/request_forgery_protection.rb +250 -29
  40. data/lib/action_controller/metal/streaming.rb +30 -38
  41. data/lib/action_controller/metal/strong_parameters.rb +669 -0
  42. data/lib/action_controller/metal/testing.rb +12 -18
  43. data/lib/action_controller/metal/url_for.rb +31 -29
  44. data/lib/action_controller/metal.rb +31 -40
  45. data/lib/action_controller/model_naming.rb +12 -0
  46. data/lib/action_controller/railtie.rb +38 -18
  47. data/lib/action_controller/railties/helpers.rb +22 -0
  48. data/lib/action_controller/test_case.rb +359 -173
  49. data/lib/action_controller.rb +9 -16
  50. data/lib/action_dispatch/http/cache.rb +64 -11
  51. data/lib/action_dispatch/http/filter_parameters.rb +20 -10
  52. data/lib/action_dispatch/http/filter_redirect.rb +38 -0
  53. data/lib/action_dispatch/http/headers.rb +85 -17
  54. data/lib/action_dispatch/http/mime_negotiation.rb +55 -5
  55. data/lib/action_dispatch/http/mime_type.rb +167 -114
  56. data/lib/action_dispatch/http/mime_types.rb +2 -1
  57. data/lib/action_dispatch/http/parameter_filter.rb +44 -46
  58. data/lib/action_dispatch/http/parameters.rb +30 -46
  59. data/lib/action_dispatch/http/rack_cache.rb +2 -3
  60. data/lib/action_dispatch/http/request.rb +108 -45
  61. data/lib/action_dispatch/http/response.rb +247 -48
  62. data/lib/action_dispatch/http/upload.rb +60 -29
  63. data/lib/action_dispatch/http/url.rb +135 -45
  64. data/lib/action_dispatch/journey/backwards.rb +5 -0
  65. data/lib/action_dispatch/journey/formatter.rb +166 -0
  66. data/lib/action_dispatch/journey/gtg/builder.rb +162 -0
  67. data/lib/action_dispatch/journey/gtg/simulator.rb +47 -0
  68. data/lib/action_dispatch/journey/gtg/transition_table.rb +157 -0
  69. data/lib/action_dispatch/journey/nfa/builder.rb +76 -0
  70. data/lib/action_dispatch/journey/nfa/dot.rb +36 -0
  71. data/lib/action_dispatch/journey/nfa/simulator.rb +47 -0
  72. data/lib/action_dispatch/journey/nfa/transition_table.rb +163 -0
  73. data/lib/action_dispatch/journey/nodes/node.rb +128 -0
  74. data/lib/action_dispatch/journey/parser.rb +198 -0
  75. data/lib/action_dispatch/journey/parser.y +49 -0
  76. data/lib/action_dispatch/journey/parser_extras.rb +23 -0
  77. data/lib/action_dispatch/journey/path/pattern.rb +193 -0
  78. data/lib/action_dispatch/journey/route.rb +125 -0
  79. data/lib/action_dispatch/journey/router/strexp.rb +27 -0
  80. data/lib/action_dispatch/journey/router/utils.rb +93 -0
  81. data/lib/action_dispatch/journey/router.rb +144 -0
  82. data/lib/action_dispatch/journey/routes.rb +80 -0
  83. data/lib/action_dispatch/journey/scanner.rb +61 -0
  84. data/lib/action_dispatch/journey/visitors.rb +221 -0
  85. data/lib/action_dispatch/journey/visualizer/fsm.css +30 -0
  86. data/lib/action_dispatch/journey/visualizer/fsm.js +134 -0
  87. data/lib/action_dispatch/journey/visualizer/index.html.erb +52 -0
  88. data/lib/action_dispatch/journey.rb +5 -0
  89. data/lib/action_dispatch/middleware/callbacks.rb +16 -11
  90. data/lib/action_dispatch/middleware/cookies.rb +346 -125
  91. data/lib/action_dispatch/middleware/debug_exceptions.rb +52 -24
  92. data/lib/action_dispatch/middleware/exception_wrapper.rb +75 -9
  93. data/lib/action_dispatch/middleware/flash.rb +85 -72
  94. data/lib/action_dispatch/middleware/params_parser.rb +16 -31
  95. data/lib/action_dispatch/middleware/public_exceptions.rb +39 -14
  96. data/lib/action_dispatch/middleware/reloader.rb +16 -7
  97. data/lib/action_dispatch/middleware/remote_ip.rb +132 -40
  98. data/lib/action_dispatch/middleware/request_id.rb +3 -7
  99. data/lib/action_dispatch/middleware/session/abstract_store.rb +22 -20
  100. data/lib/action_dispatch/middleware/session/cache_store.rb +3 -3
  101. data/lib/action_dispatch/middleware/session/cookie_store.rb +84 -29
  102. data/lib/action_dispatch/middleware/session/mem_cache_store.rb +8 -3
  103. data/lib/action_dispatch/middleware/show_exceptions.rb +15 -44
  104. data/lib/action_dispatch/middleware/ssl.rb +72 -0
  105. data/lib/action_dispatch/middleware/stack.rb +6 -1
  106. data/lib/action_dispatch/middleware/static.rb +80 -23
  107. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +34 -0
  108. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +23 -0
  109. data/lib/action_dispatch/middleware/templates/rescues/_source.erb +27 -0
  110. data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +52 -0
  111. data/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +9 -0
  112. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +16 -0
  113. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +9 -0
  114. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +133 -5
  115. data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +11 -0
  116. data/lib/action_dispatch/middleware/templates/rescues/missing_template.text.erb +3 -0
  117. data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +32 -0
  118. data/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb +11 -0
  119. data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +20 -0
  120. data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +7 -0
  121. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +6 -0
  122. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +3 -0
  123. data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +16 -0
  124. data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +200 -0
  125. data/lib/action_dispatch/railtie.rb +19 -6
  126. data/lib/action_dispatch/request/session.rb +193 -0
  127. data/lib/action_dispatch/request/utils.rb +35 -0
  128. data/lib/action_dispatch/routing/endpoint.rb +10 -0
  129. data/lib/action_dispatch/routing/inspector.rb +234 -0
  130. data/lib/action_dispatch/routing/mapper.rb +897 -436
  131. data/lib/action_dispatch/routing/polymorphic_routes.rb +213 -92
  132. data/lib/action_dispatch/routing/redirection.rb +97 -37
  133. data/lib/action_dispatch/routing/route_set.rb +432 -239
  134. data/lib/action_dispatch/routing/routes_proxy.rb +7 -4
  135. data/lib/action_dispatch/routing/url_for.rb +63 -34
  136. data/lib/action_dispatch/routing.rb +57 -89
  137. data/lib/action_dispatch/testing/assertions/dom.rb +2 -36
  138. data/lib/action_dispatch/testing/assertions/response.rb +24 -38
  139. data/lib/action_dispatch/testing/assertions/routing.rb +55 -54
  140. data/lib/action_dispatch/testing/assertions/selector.rb +2 -434
  141. data/lib/action_dispatch/testing/assertions/tag.rb +2 -137
  142. data/lib/action_dispatch/testing/assertions.rb +11 -7
  143. data/lib/action_dispatch/testing/integration.rb +88 -72
  144. data/lib/action_dispatch/testing/test_process.rb +9 -6
  145. data/lib/action_dispatch/testing/test_request.rb +13 -9
  146. data/lib/action_dispatch/testing/test_response.rb +1 -5
  147. data/lib/action_dispatch.rb +24 -21
  148. data/lib/action_pack/gem_version.rb +15 -0
  149. data/lib/action_pack/version.rb +5 -7
  150. data/lib/action_pack.rb +1 -1
  151. metadata +181 -292
  152. data/lib/abstract_controller/layouts.rb +0 -423
  153. data/lib/abstract_controller/view_paths.rb +0 -96
  154. data/lib/action_controller/caching/actions.rb +0 -185
  155. data/lib/action_controller/caching/pages.rb +0 -187
  156. data/lib/action_controller/caching/sweeping.rb +0 -97
  157. data/lib/action_controller/deprecated/integration_test.rb +0 -2
  158. data/lib/action_controller/deprecated/performance_test.rb +0 -1
  159. data/lib/action_controller/deprecated.rb +0 -3
  160. data/lib/action_controller/metal/compatibility.rb +0 -65
  161. data/lib/action_controller/metal/responder.rb +0 -286
  162. data/lib/action_controller/metal/session_management.rb +0 -14
  163. data/lib/action_controller/railties/paths.rb +0 -25
  164. data/lib/action_controller/record_identifier.rb +0 -85
  165. data/lib/action_controller/vendor/html-scanner/html/document.rb +0 -68
  166. data/lib/action_controller/vendor/html-scanner/html/node.rb +0 -532
  167. data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +0 -177
  168. data/lib/action_controller/vendor/html-scanner/html/selector.rb +0 -830
  169. data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +0 -107
  170. data/lib/action_controller/vendor/html-scanner/html/version.rb +0 -11
  171. data/lib/action_controller/vendor/html-scanner.rb +0 -20
  172. data/lib/action_dispatch/middleware/best_standards_support.rb +0 -30
  173. data/lib/action_dispatch/middleware/body_proxy.rb +0 -30
  174. data/lib/action_dispatch/middleware/head.rb +0 -18
  175. data/lib/action_dispatch/middleware/rescue.rb +0 -26
  176. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb +0 -31
  177. data/lib/action_dispatch/middleware/templates/rescues/_trace.erb +0 -26
  178. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb +0 -10
  179. data/lib/action_dispatch/middleware/templates/rescues/missing_template.erb +0 -2
  180. data/lib/action_dispatch/middleware/templates/rescues/routing_error.erb +0 -15
  181. data/lib/action_dispatch/middleware/templates/rescues/template_error.erb +0 -17
  182. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb +0 -2
  183. data/lib/action_dispatch/testing/performance_test.rb +0 -10
  184. data/lib/action_view/asset_paths.rb +0 -142
  185. data/lib/action_view/base.rb +0 -220
  186. data/lib/action_view/buffers.rb +0 -43
  187. data/lib/action_view/context.rb +0 -36
  188. data/lib/action_view/flows.rb +0 -79
  189. data/lib/action_view/helpers/active_model_helper.rb +0 -50
  190. data/lib/action_view/helpers/asset_paths.rb +0 -7
  191. data/lib/action_view/helpers/asset_tag_helper.rb +0 -457
  192. data/lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb +0 -146
  193. data/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb +0 -93
  194. data/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +0 -193
  195. data/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +0 -148
  196. data/lib/action_view/helpers/atom_feed_helper.rb +0 -200
  197. data/lib/action_view/helpers/cache_helper.rb +0 -64
  198. data/lib/action_view/helpers/capture_helper.rb +0 -203
  199. data/lib/action_view/helpers/controller_helper.rb +0 -25
  200. data/lib/action_view/helpers/csrf_helper.rb +0 -32
  201. data/lib/action_view/helpers/date_helper.rb +0 -1062
  202. data/lib/action_view/helpers/debug_helper.rb +0 -40
  203. data/lib/action_view/helpers/form_helper.rb +0 -1486
  204. data/lib/action_view/helpers/form_options_helper.rb +0 -658
  205. data/lib/action_view/helpers/form_tag_helper.rb +0 -685
  206. data/lib/action_view/helpers/javascript_helper.rb +0 -110
  207. data/lib/action_view/helpers/number_helper.rb +0 -622
  208. data/lib/action_view/helpers/output_safety_helper.rb +0 -38
  209. data/lib/action_view/helpers/record_tag_helper.rb +0 -111
  210. data/lib/action_view/helpers/rendering_helper.rb +0 -90
  211. data/lib/action_view/helpers/sanitize_helper.rb +0 -259
  212. data/lib/action_view/helpers/tag_helper.rb +0 -160
  213. data/lib/action_view/helpers/text_helper.rb +0 -426
  214. data/lib/action_view/helpers/translation_helper.rb +0 -91
  215. data/lib/action_view/helpers/url_helper.rb +0 -693
  216. data/lib/action_view/helpers.rb +0 -60
  217. data/lib/action_view/locale/en.yml +0 -160
  218. data/lib/action_view/log_subscriber.rb +0 -28
  219. data/lib/action_view/lookup_context.rb +0 -254
  220. data/lib/action_view/path_set.rb +0 -89
  221. data/lib/action_view/railtie.rb +0 -55
  222. data/lib/action_view/renderer/abstract_renderer.rb +0 -41
  223. data/lib/action_view/renderer/partial_renderer.rb +0 -415
  224. data/lib/action_view/renderer/renderer.rb +0 -54
  225. data/lib/action_view/renderer/streaming_template_renderer.rb +0 -106
  226. data/lib/action_view/renderer/template_renderer.rb +0 -94
  227. data/lib/action_view/template/error.rb +0 -128
  228. data/lib/action_view/template/handlers/builder.rb +0 -26
  229. data/lib/action_view/template/handlers/erb.rb +0 -125
  230. data/lib/action_view/template/handlers.rb +0 -50
  231. data/lib/action_view/template/resolver.rb +0 -272
  232. data/lib/action_view/template/text.rb +0 -30
  233. data/lib/action_view/template.rb +0 -337
  234. data/lib/action_view/test_case.rb +0 -245
  235. data/lib/action_view/testing/resolvers.rb +0 -50
  236. data/lib/action_view.rb +0 -84
  237. data/lib/sprockets/assets.rake +0 -99
  238. data/lib/sprockets/bootstrap.rb +0 -37
  239. data/lib/sprockets/compressors.rb +0 -83
  240. data/lib/sprockets/helpers/isolated_helper.rb +0 -13
  241. data/lib/sprockets/helpers/rails_helper.rb +0 -182
  242. data/lib/sprockets/helpers.rb +0 -6
  243. data/lib/sprockets/railtie.rb +0 -62
  244. 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-2014 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,309 +10,19 @@ 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
 
@@ -322,12 +32,14 @@ The latest version of Action Pack can be installed with RubyGems:
322
32
 
323
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/4-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
+ * http://www.opensource.org/licenses/MIT
331
43
 
332
44
 
333
45
  == Support
@@ -336,6 +48,11 @@ 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 can be filed for the Ruby on Rails project 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
58
+
@@ -1,9 +1,9 @@
1
1
  module AbstractController
2
- module AssetPaths
2
+ module AssetPaths #:nodoc:
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- config_accessor :asset_host, :asset_path, :assets_dir, :javascripts_dir,
6
+ config_accessor :asset_host, :assets_dir, :javascripts_dir,
7
7
  :stylesheets_dir, :default_asset_host_protocol, :relative_url_root
8
8
  end
9
9
  end
@@ -1,11 +1,16 @@
1
1
  require 'erubis'
2
+ require 'set'
2
3
  require 'active_support/configurable'
3
4
  require 'active_support/descendants_tracker'
4
5
  require 'active_support/core_ext/module/anonymous'
5
6
 
6
7
  module AbstractController
7
- class Error < StandardError; end
8
- class ActionNotFound < StandardError; end
8
+ class Error < StandardError #:nodoc:
9
+ end
10
+
11
+ # Raised when a non-existing controller action is triggered.
12
+ class ActionNotFound < StandardError
13
+ end
9
14
 
10
15
  # <tt>AbstractController::Base</tt> is a low-level API. Nobody should be
11
16
  # using it directly, and subclasses (like ActionController::Base) are
@@ -30,6 +35,15 @@ module AbstractController
30
35
  @abstract = true
31
36
  end
32
37
 
38
+ def inherited(klass) # :nodoc:
39
+ # Define the abstract ivar on subclasses so that we don't get
40
+ # uninitialized ivar warnings
41
+ unless klass.instance_variable_defined?(:@abstract)
42
+ klass.instance_variable_set(:@abstract, false)
43
+ end
44
+ super
45
+ end
46
+
33
47
  # A list of all internal methods for a controller. This finds the first
34
48
  # abstract superclass of a controller, and gets a list of all public
35
49
  # instance methods on that abstract class. Public instance methods of
@@ -38,16 +52,17 @@ module AbstractController
38
52
  # (ActionController::Metal and ActionController::Base are defined as abstract)
39
53
  def internal_methods
40
54
  controller = self
55
+
41
56
  controller = controller.superclass until controller.abstract?
42
57
  controller.public_instance_methods(true)
43
58
  end
44
59
 
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
60
+ # The list of hidden actions. Defaults to an empty array.
61
+ # This can be modified by other modules or subclasses
47
62
  # to specify particular actions as hidden.
48
63
  #
49
64
  # ==== Returns
50
- # * <tt>array</tt> - An array of method names that should not be considered actions.
65
+ # * <tt>Array</tt> - An array of method names that should not be considered actions.
51
66
  def hidden_actions
52
67
  []
53
68
  end
@@ -59,7 +74,7 @@ module AbstractController
59
74
  # itself. Finally, #hidden_actions are removed.
60
75
  #
61
76
  # ==== Returns
62
- # * <tt>array</tt> - A list of all methods that should be considered actions.
77
+ # * <tt>Set</tt> - A set of all methods that should be considered actions.
63
78
  def action_methods
64
79
  @action_methods ||= begin
65
80
  # All public instance methods of this class, including ancestors
@@ -72,7 +87,7 @@ module AbstractController
72
87
  hidden_actions.to_a
73
88
 
74
89
  # Clear out AS callback method pollution
75
- methods.reject { |method| method =~ /_one_time_conditions/ }
90
+ Set.new(methods.reject { |method| method =~ /_one_time_conditions/ })
76
91
  end
77
92
  end
78
93
 
@@ -85,14 +100,15 @@ module AbstractController
85
100
 
86
101
  # Returns the full controller name, underscored, without the ending Controller.
87
102
  # For instance, MyApp::MyPostsController would return "my_app/my_posts" for
88
- # controller_name.
103
+ # controller_path.
89
104
  #
90
105
  # ==== Returns
91
- # * <tt>string</tt>
106
+ # * <tt>String</tt>
92
107
  def controller_path
93
108
  @controller_path ||= name.sub(/Controller$/, '').underscore unless anonymous?
94
109
  end
95
110
 
111
+ # Refresh the cached action_methods when a new action_method is added.
96
112
  def method_added(name)
97
113
  super
98
114
  clear_action_methods!
@@ -105,14 +121,14 @@ module AbstractController
105
121
  #
106
122
  # The actual method that is called is determined by calling
107
123
  # #method_for_action. If no method can handle the action, then an
108
- # ActionNotFound error is raised.
124
+ # AbstractController::ActionNotFound error is raised.
109
125
  #
110
126
  # ==== Returns
111
127
  # * <tt>self</tt>
112
128
  def process(action, *args)
113
- @_action_name = action_name = action.to_s
129
+ @_action_name = action.to_s
114
130
 
115
- unless action_name = _find_action_name(action_name)
131
+ unless action_name = _find_action_name(@_action_name)
116
132
  raise ActionNotFound, "The action '#{action}' could not be found for #{self.class.name}"
117
133
  end
118
134
 
@@ -126,6 +142,7 @@ module AbstractController
126
142
  self.class.controller_path
127
143
  end
128
144
 
145
+ # Delegates to the class' #action_methods
129
146
  def action_methods
130
147
  self.class.action_methods
131
148
  end
@@ -135,12 +152,26 @@ module AbstractController
135
152
  #
136
153
  # Notice that <tt>action_methods.include?("foo")</tt> may return
137
154
  # false and <tt>available_action?("foo")</tt> returns true because
138
- # available action consider actions that are also available
155
+ # this method considers actions that are also available
139
156
  # through other means, for example, implicit render ones.
157
+ #
158
+ # ==== Parameters
159
+ # * <tt>action_name</tt> - The name of an action to be tested
160
+ #
161
+ # ==== Returns
162
+ # * <tt>TrueClass</tt>, <tt>FalseClass</tt>
140
163
  def available_action?(action_name)
141
164
  _find_action_name(action_name).present?
142
165
  end
143
166
 
167
+ # Returns true if the given controller is capable of rendering
168
+ # a path. A subclass of +AbstractController::Base+
169
+ # may return false. An Email controller for example does not
170
+ # support paths, only full URLs.
171
+ def self.supports_path?
172
+ true
173
+ end
174
+
144
175
  private
145
176
 
146
177
  # Returns true if the name can be considered an action because
@@ -193,7 +224,8 @@ module AbstractController
193
224
  #
194
225
  # ==== Returns
195
226
  # * <tt>string</tt> - The name of the method that handles the action
196
- # * false - No valid method name could be found. Raise ActionNotFound.
227
+ # * false - No valid method name could be found.
228
+ # Raise AbstractController::ActionNotFound.
197
229
  def _find_action_name(action_name)
198
230
  _valid_action_name?(action_name) && method_for_action(action_name)
199
231
  end
@@ -213,7 +245,7 @@ module AbstractController
213
245
  # the case.
214
246
  #
215
247
  # If none of these conditions are true, and method_for_action
216
- # returns nil, an ActionNotFound exception will be raised.
248
+ # returns nil, an AbstractController::ActionNotFound exception will be raised.
217
249
  #
218
250
  # ==== Parameters
219
251
  # * <tt>action_name</tt> - An action name to find a method name for
@@ -222,14 +254,16 @@ module AbstractController
222
254
  # * <tt>string</tt> - The name of the method that handles the action
223
255
  # * <tt>nil</tt> - No method name could be found.
224
256
  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"
257
+ if action_method?(action_name)
258
+ action_name
259
+ elsif respond_to?(:action_missing, true)
260
+ "_handle_action_missing"
227
261
  end
228
262
  end
229
263
 
230
264
  # Checks if the action name is valid and returns false otherwise.
231
265
  def _valid_action_name?(action_name)
232
- action_name.to_s !~ Regexp.new(File::SEPARATOR)
266
+ !action_name.to_s.include? File::SEPARATOR
233
267
  end
234
268
  end
235
269
  end