actionpack 3.2.22.5 → 4.0.0.beta1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +641 -418
- data/MIT-LICENSE +1 -1
- data/README.rdoc +5 -288
- data/lib/abstract_controller.rb +1 -8
- data/lib/abstract_controller/asset_paths.rb +2 -2
- data/lib/abstract_controller/base.rb +39 -37
- data/lib/abstract_controller/callbacks.rb +101 -82
- data/lib/abstract_controller/collector.rb +7 -3
- data/lib/abstract_controller/helpers.rb +23 -11
- data/lib/abstract_controller/layouts.rb +68 -73
- data/lib/abstract_controller/logger.rb +1 -2
- data/lib/abstract_controller/rendering.rb +22 -13
- data/lib/abstract_controller/translation.rb +16 -1
- data/lib/abstract_controller/url_for.rb +6 -6
- data/lib/abstract_controller/view_paths.rb +1 -1
- data/lib/action_controller.rb +15 -6
- data/lib/action_controller/base.rb +46 -22
- data/lib/action_controller/caching.rb +46 -33
- data/lib/action_controller/caching/fragments.rb +23 -53
- data/lib/action_controller/deprecated.rb +5 -1
- data/lib/action_controller/deprecated/integration_test.rb +3 -0
- data/lib/action_controller/log_subscriber.rb +11 -8
- data/lib/action_controller/metal.rb +16 -30
- data/lib/action_controller/metal/conditional_get.rb +76 -32
- data/lib/action_controller/metal/data_streaming.rb +20 -26
- data/lib/action_controller/metal/exceptions.rb +19 -6
- data/lib/action_controller/metal/flash.rb +24 -9
- data/lib/action_controller/metal/force_ssl.rb +32 -9
- data/lib/action_controller/metal/head.rb +25 -4
- data/lib/action_controller/metal/helpers.rb +6 -9
- data/lib/action_controller/metal/hide_actions.rb +1 -2
- data/lib/action_controller/metal/http_authentication.rb +105 -87
- data/lib/action_controller/metal/implicit_render.rb +1 -1
- data/lib/action_controller/metal/instrumentation.rb +2 -1
- data/lib/action_controller/metal/live.rb +141 -0
- data/lib/action_controller/metal/mime_responds.rb +161 -47
- data/lib/action_controller/metal/params_wrapper.rb +112 -74
- data/lib/action_controller/metal/rack_delegation.rb +9 -3
- data/lib/action_controller/metal/redirecting.rb +15 -20
- data/lib/action_controller/metal/renderers.rb +11 -9
- data/lib/action_controller/metal/rendering.rb +8 -0
- data/lib/action_controller/metal/request_forgery_protection.rb +112 -19
- data/lib/action_controller/metal/responder.rb +20 -19
- data/lib/action_controller/metal/streaming.rb +12 -18
- data/lib/action_controller/metal/strong_parameters.rb +516 -0
- data/lib/action_controller/metal/testing.rb +13 -18
- data/lib/action_controller/metal/url_for.rb +27 -25
- data/lib/action_controller/model_naming.rb +12 -0
- data/lib/action_controller/railtie.rb +33 -17
- data/lib/action_controller/railties/helpers.rb +22 -0
- data/lib/action_controller/record_identifier.rb +18 -72
- data/lib/action_controller/test_case.rb +215 -123
- data/lib/action_controller/vendor/html-scanner.rb +4 -19
- data/lib/action_dispatch.rb +27 -19
- data/lib/action_dispatch/http/cache.rb +63 -11
- data/lib/action_dispatch/http/filter_parameters.rb +18 -8
- data/lib/action_dispatch/http/filter_redirect.rb +37 -0
- data/lib/action_dispatch/http/headers.rb +27 -19
- data/lib/action_dispatch/http/mime_negotiation.rb +25 -2
- data/lib/action_dispatch/http/mime_type.rb +145 -113
- data/lib/action_dispatch/http/mime_types.rb +1 -1
- data/lib/action_dispatch/http/parameter_filter.rb +44 -46
- data/lib/action_dispatch/http/parameters.rb +12 -5
- data/lib/action_dispatch/http/rack_cache.rb +2 -3
- data/lib/action_dispatch/http/request.rb +49 -18
- data/lib/action_dispatch/http/response.rb +129 -35
- data/lib/action_dispatch/http/upload.rb +60 -17
- data/lib/action_dispatch/http/url.rb +53 -31
- data/lib/action_dispatch/journey.rb +5 -0
- data/lib/action_dispatch/journey/backwards.rb +5 -0
- data/lib/action_dispatch/journey/formatter.rb +146 -0
- data/lib/action_dispatch/journey/gtg/builder.rb +162 -0
- data/lib/action_dispatch/journey/gtg/simulator.rb +44 -0
- data/lib/action_dispatch/journey/gtg/transition_table.rb +156 -0
- data/lib/action_dispatch/journey/nfa/builder.rb +76 -0
- data/lib/action_dispatch/journey/nfa/dot.rb +36 -0
- data/lib/action_dispatch/journey/nfa/simulator.rb +47 -0
- data/lib/action_dispatch/journey/nfa/transition_table.rb +163 -0
- data/lib/action_dispatch/journey/nodes/node.rb +124 -0
- data/lib/action_dispatch/journey/parser.rb +206 -0
- data/lib/action_dispatch/journey/parser.y +47 -0
- data/lib/action_dispatch/journey/parser_extras.rb +23 -0
- data/lib/action_dispatch/journey/path/pattern.rb +196 -0
- data/lib/action_dispatch/journey/route.rb +116 -0
- data/lib/action_dispatch/journey/router.rb +164 -0
- data/lib/action_dispatch/journey/router/strexp.rb +24 -0
- data/lib/action_dispatch/journey/router/utils.rb +54 -0
- data/lib/action_dispatch/journey/routes.rb +75 -0
- data/lib/action_dispatch/journey/scanner.rb +61 -0
- data/lib/action_dispatch/journey/visitors.rb +189 -0
- data/lib/action_dispatch/journey/visualizer/fsm.css +34 -0
- data/lib/action_dispatch/journey/visualizer/fsm.js +134 -0
- data/lib/action_dispatch/journey/visualizer/index.html.erb +52 -0
- data/lib/action_dispatch/middleware/callbacks.rb +9 -4
- data/lib/action_dispatch/middleware/cookies.rb +168 -57
- data/lib/action_dispatch/middleware/debug_exceptions.rb +26 -17
- data/lib/action_dispatch/middleware/exception_wrapper.rb +27 -3
- data/lib/action_dispatch/middleware/flash.rb +58 -58
- data/lib/action_dispatch/middleware/params_parser.rb +14 -29
- data/lib/action_dispatch/middleware/public_exceptions.rb +31 -14
- data/lib/action_dispatch/middleware/reloader.rb +6 -6
- data/lib/action_dispatch/middleware/remote_ip.rb +145 -39
- data/lib/action_dispatch/middleware/request_id.rb +2 -6
- data/lib/action_dispatch/middleware/session/abstract_store.rb +22 -20
- data/lib/action_dispatch/middleware/session/cache_store.rb +3 -3
- data/lib/action_dispatch/middleware/session/cookie_store.rb +81 -7
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +8 -3
- data/lib/action_dispatch/middleware/show_exceptions.rb +12 -45
- data/lib/action_dispatch/middleware/ssl.rb +70 -0
- data/lib/action_dispatch/middleware/stack.rb +6 -1
- data/lib/action_dispatch/middleware/static.rb +5 -24
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb +14 -11
- data/lib/action_dispatch/middleware/templates/rescues/_source.erb +25 -0
- data/lib/action_dispatch/middleware/templates/rescues/_trace.erb +3 -3
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb +15 -9
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +121 -5
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.erb +7 -2
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.erb +30 -15
- data/lib/action_dispatch/middleware/templates/rescues/template_error.erb +39 -13
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb +6 -2
- data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +16 -0
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +144 -0
- data/lib/action_dispatch/railtie.rb +16 -6
- data/lib/action_dispatch/request/session.rb +181 -0
- data/lib/action_dispatch/routing.rb +41 -40
- data/lib/action_dispatch/routing/inspector.rb +240 -0
- data/lib/action_dispatch/routing/mapper.rb +501 -273
- data/lib/action_dispatch/routing/polymorphic_routes.rb +16 -20
- data/lib/action_dispatch/routing/redirection.rb +46 -29
- data/lib/action_dispatch/routing/route_set.rb +203 -164
- data/lib/action_dispatch/routing/routes_proxy.rb +2 -0
- data/lib/action_dispatch/routing/url_for.rb +48 -33
- data/lib/action_dispatch/testing/assertions/dom.rb +3 -13
- data/lib/action_dispatch/testing/assertions/response.rb +32 -40
- data/lib/action_dispatch/testing/assertions/routing.rb +40 -39
- data/lib/action_dispatch/testing/assertions/selector.rb +15 -20
- data/lib/action_dispatch/testing/assertions/tag.rb +20 -23
- data/lib/action_dispatch/testing/integration.rb +41 -22
- data/lib/action_dispatch/testing/test_process.rb +9 -6
- data/lib/action_dispatch/testing/test_request.rb +7 -3
- data/lib/action_pack.rb +1 -1
- data/lib/action_pack/version.rb +4 -4
- data/lib/action_view.rb +17 -8
- data/lib/action_view/base.rb +15 -34
- data/lib/action_view/buffers.rb +1 -1
- data/lib/action_view/context.rb +4 -4
- data/lib/action_view/dependency_tracker.rb +91 -0
- data/lib/action_view/digestor.rb +85 -0
- data/lib/action_view/flows.rb +1 -4
- data/lib/action_view/helpers.rb +2 -4
- data/lib/action_view/helpers/active_model_helper.rb +3 -4
- data/lib/action_view/helpers/asset_tag_helper.rb +211 -353
- data/lib/action_view/helpers/asset_url_helper.rb +354 -0
- data/lib/action_view/helpers/atom_feed_helper.rb +13 -10
- data/lib/action_view/helpers/cache_helper.rb +150 -18
- data/lib/action_view/helpers/capture_helper.rb +42 -29
- data/lib/action_view/helpers/csrf_helper.rb +0 -2
- data/lib/action_view/helpers/date_helper.rb +268 -247
- data/lib/action_view/helpers/debug_helper.rb +10 -11
- data/lib/action_view/helpers/form_helper.rb +904 -547
- data/lib/action_view/helpers/form_options_helper.rb +341 -166
- data/lib/action_view/helpers/form_tag_helper.rb +188 -88
- data/lib/action_view/helpers/javascript_helper.rb +23 -16
- data/lib/action_view/helpers/number_helper.rb +148 -354
- data/lib/action_view/helpers/output_safety_helper.rb +3 -3
- data/lib/action_view/helpers/record_tag_helper.rb +17 -22
- data/lib/action_view/helpers/rendering_helper.rb +2 -4
- data/lib/action_view/helpers/sanitize_helper.rb +3 -6
- data/lib/action_view/helpers/tag_helper.rb +43 -37
- data/lib/action_view/helpers/tags.rb +39 -0
- data/lib/action_view/helpers/tags/base.rb +148 -0
- data/lib/action_view/helpers/tags/check_box.rb +64 -0
- data/lib/action_view/helpers/tags/checkable.rb +16 -0
- data/lib/action_view/helpers/tags/collection_check_boxes.rb +43 -0
- data/lib/action_view/helpers/tags/collection_helpers.rb +83 -0
- data/lib/action_view/helpers/tags/collection_radio_buttons.rb +36 -0
- data/lib/action_view/helpers/tags/collection_select.rb +28 -0
- data/lib/action_view/helpers/tags/color_field.rb +25 -0
- data/lib/action_view/helpers/tags/date_field.rb +13 -0
- data/lib/action_view/helpers/tags/date_select.rb +72 -0
- data/lib/action_view/helpers/tags/datetime_field.rb +22 -0
- data/lib/action_view/helpers/tags/datetime_local_field.rb +19 -0
- data/lib/action_view/helpers/tags/datetime_select.rb +8 -0
- data/lib/action_view/helpers/tags/email_field.rb +8 -0
- data/lib/action_view/helpers/tags/file_field.rb +8 -0
- data/lib/action_view/helpers/tags/grouped_collection_select.rb +29 -0
- data/lib/action_view/helpers/tags/hidden_field.rb +8 -0
- data/lib/action_view/helpers/tags/label.rb +65 -0
- data/lib/action_view/helpers/tags/month_field.rb +13 -0
- data/lib/action_view/helpers/tags/number_field.rb +18 -0
- data/lib/action_view/helpers/tags/password_field.rb +12 -0
- data/lib/action_view/helpers/tags/radio_button.rb +31 -0
- data/lib/action_view/helpers/tags/range_field.rb +8 -0
- data/lib/action_view/helpers/tags/search_field.rb +24 -0
- data/lib/action_view/helpers/tags/select.rb +41 -0
- data/lib/action_view/helpers/tags/tel_field.rb +8 -0
- data/lib/action_view/helpers/tags/text_area.rb +18 -0
- data/lib/action_view/helpers/tags/text_field.rb +29 -0
- data/lib/action_view/helpers/tags/time_field.rb +13 -0
- data/lib/action_view/helpers/tags/time_select.rb +8 -0
- data/lib/action_view/helpers/tags/time_zone_select.rb +20 -0
- data/lib/action_view/helpers/tags/url_field.rb +8 -0
- data/lib/action_view/helpers/tags/week_field.rb +13 -0
- data/lib/action_view/helpers/text_helper.rb +126 -113
- data/lib/action_view/helpers/translation_helper.rb +32 -16
- data/lib/action_view/helpers/url_helper.rb +200 -271
- data/lib/action_view/locale/en.yml +1 -105
- data/lib/action_view/log_subscriber.rb +6 -4
- data/lib/action_view/lookup_context.rb +15 -39
- data/lib/action_view/model_naming.rb +12 -0
- data/lib/action_view/path_set.rb +9 -39
- data/lib/action_view/railtie.rb +6 -22
- data/lib/action_view/record_identifier.rb +84 -0
- data/lib/action_view/renderer/abstract_renderer.rb +10 -19
- data/lib/action_view/renderer/partial_renderer.rb +144 -81
- data/lib/action_view/renderer/renderer.rb +2 -19
- data/lib/action_view/renderer/streaming_template_renderer.rb +2 -5
- data/lib/action_view/renderer/template_renderer.rb +14 -13
- data/lib/action_view/routing_url_for.rb +107 -0
- data/lib/action_view/template.rb +22 -21
- data/lib/action_view/template/error.rb +22 -12
- data/lib/action_view/template/handlers.rb +12 -9
- data/lib/action_view/template/handlers/builder.rb +1 -1
- data/lib/action_view/template/handlers/erb.rb +11 -16
- data/lib/action_view/template/handlers/raw.rb +11 -0
- data/lib/action_view/template/resolver.rb +111 -83
- data/lib/action_view/template/text.rb +12 -8
- data/lib/action_view/template/types.rb +57 -0
- data/lib/action_view/test_case.rb +66 -43
- data/lib/action_view/testing/resolvers.rb +3 -2
- data/lib/action_view/vendor/html-scanner.rb +20 -0
- data/lib/{action_controller → action_view}/vendor/html-scanner/html/document.rb +0 -0
- data/lib/{action_controller → action_view}/vendor/html-scanner/html/node.rb +12 -12
- data/lib/{action_controller → action_view}/vendor/html-scanner/html/sanitizer.rb +18 -7
- data/lib/{action_controller → action_view}/vendor/html-scanner/html/selector.rb +1 -1
- data/lib/{action_controller → action_view}/vendor/html-scanner/html/tokenizer.rb +1 -1
- data/lib/{action_controller → action_view}/vendor/html-scanner/html/version.rb +0 -0
- metadata +135 -125
- data/lib/action_controller/caching/actions.rb +0 -185
- data/lib/action_controller/caching/pages.rb +0 -187
- data/lib/action_controller/caching/sweeping.rb +0 -97
- data/lib/action_controller/deprecated/performance_test.rb +0 -1
- data/lib/action_controller/metal/compatibility.rb +0 -65
- data/lib/action_controller/metal/session_management.rb +0 -14
- data/lib/action_controller/railties/paths.rb +0 -25
- data/lib/action_dispatch/middleware/best_standards_support.rb +0 -30
- data/lib/action_dispatch/middleware/body_proxy.rb +0 -30
- data/lib/action_dispatch/middleware/head.rb +0 -18
- data/lib/action_dispatch/middleware/rescue.rb +0 -26
- data/lib/action_dispatch/testing/performance_test.rb +0 -10
- data/lib/action_view/asset_paths.rb +0 -142
- data/lib/action_view/helpers/asset_paths.rb +0 -7
- data/lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb +0 -146
- data/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb +0 -93
- data/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +0 -193
- data/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +0 -148
- data/lib/sprockets/assets.rake +0 -99
- data/lib/sprockets/bootstrap.rb +0 -37
- data/lib/sprockets/compressors.rb +0 -83
- data/lib/sprockets/helpers.rb +0 -6
- data/lib/sprockets/helpers/isolated_helper.rb +0 -13
- data/lib/sprockets/helpers/rails_helper.rb +0 -182
- data/lib/sprockets/railtie.rb +0 -62
- data/lib/sprockets/static_compiler.rb +0 -56
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -10,7 +10,7 @@ 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
|
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
|
@@ -28,291 +28,6 @@ by default and Action View rendering is implicitly triggered by Action
|
|
28
28
|
Controller. However, these modules are designed to function on their own and
|
29
29
|
can be used outside of Rails.
|
30
30
|
|
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
31
|
|
317
32
|
== Download and installation
|
318
33
|
|
@@ -322,12 +37,14 @@ The latest version of Action Pack can be installed with RubyGems:
|
|
322
37
|
|
323
38
|
Source code can be downloaded as part of the Rails project on GitHub
|
324
39
|
|
325
|
-
* https://github.com/rails/rails/tree/
|
40
|
+
* https://github.com/rails/rails/tree/master/actionpack
|
326
41
|
|
327
42
|
|
328
43
|
== License
|
329
44
|
|
330
|
-
Action Pack is released under the MIT license
|
45
|
+
Action Pack is released under the MIT license:
|
46
|
+
|
47
|
+
* http://www.opensource.org/licenses/MIT
|
331
48
|
|
332
49
|
|
333
50
|
== Support
|
data/lib/abstract_controller.rb
CHANGED
@@ -1,13 +1,6 @@
|
|
1
|
-
activesupport_path = File.expand_path('../../../activesupport/lib', __FILE__)
|
2
|
-
$:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path)
|
3
|
-
|
4
1
|
require 'action_pack'
|
5
|
-
require 'active_support/
|
6
|
-
require 'active_support/ruby/shim'
|
7
|
-
require 'active_support/dependencies/autoload'
|
8
|
-
require 'active_support/core_ext/class/attribute'
|
2
|
+
require 'active_support/rails'
|
9
3
|
require 'active_support/core_ext/module/attr_internal'
|
10
|
-
require 'active_support/core_ext/module/delegation'
|
11
4
|
require 'active_support/core_ext/module/anonymous'
|
12
5
|
require 'active_support/i18n'
|
13
6
|
|
@@ -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, :
|
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,15 @@
|
|
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
|
8
|
-
|
8
|
+
class Error < StandardError #:nodoc:
|
9
|
+
end
|
10
|
+
|
11
|
+
class ActionNotFound < StandardError #:nodoc:
|
12
|
+
end
|
9
13
|
|
10
14
|
# <tt>AbstractController::Base</tt> is a low-level API. Nobody should be
|
11
15
|
# using it directly, and subclasses (like ActionController::Base) are
|
@@ -30,6 +34,15 @@ module AbstractController
|
|
30
34
|
@abstract = true
|
31
35
|
end
|
32
36
|
|
37
|
+
def inherited(klass) # :nodoc:
|
38
|
+
# define the abstract ivar on subclasses so that we don't get
|
39
|
+
# uninitialized ivar warnings
|
40
|
+
unless klass.instance_variable_defined?(:@abstract)
|
41
|
+
klass.instance_variable_set(:@abstract, false)
|
42
|
+
end
|
43
|
+
super
|
44
|
+
end
|
45
|
+
|
33
46
|
# A list of all internal methods for a controller. This finds the first
|
34
47
|
# abstract superclass of a controller, and gets a list of all public
|
35
48
|
# instance methods on that abstract class. Public instance methods of
|
@@ -38,16 +51,17 @@ module AbstractController
|
|
38
51
|
# (ActionController::Metal and ActionController::Base are defined as abstract)
|
39
52
|
def internal_methods
|
40
53
|
controller = self
|
54
|
+
|
41
55
|
controller = controller.superclass until controller.abstract?
|
42
56
|
controller.public_instance_methods(true)
|
43
57
|
end
|
44
58
|
|
45
|
-
# The list of hidden actions to an empty array.
|
46
|
-
#
|
59
|
+
# The list of hidden actions. Defaults to an empty array.
|
60
|
+
# This can be modified by other modules or subclasses
|
47
61
|
# to specify particular actions as hidden.
|
48
62
|
#
|
49
63
|
# ==== Returns
|
50
|
-
# * <tt>
|
64
|
+
# * <tt>Array</tt> - An array of method names that should not be considered actions.
|
51
65
|
def hidden_actions
|
52
66
|
[]
|
53
67
|
end
|
@@ -59,7 +73,7 @@ module AbstractController
|
|
59
73
|
# itself. Finally, #hidden_actions are removed.
|
60
74
|
#
|
61
75
|
# ==== Returns
|
62
|
-
# * <tt>
|
76
|
+
# * <tt>Set</tt> - A set of all methods that should be considered actions.
|
63
77
|
def action_methods
|
64
78
|
@action_methods ||= begin
|
65
79
|
# All public instance methods of this class, including ancestors
|
@@ -72,7 +86,7 @@ module AbstractController
|
|
72
86
|
hidden_actions.to_a
|
73
87
|
|
74
88
|
# Clear out AS callback method pollution
|
75
|
-
methods.reject { |method| method =~ /_one_time_conditions/ }
|
89
|
+
Set.new(methods.reject { |method| method =~ /_one_time_conditions/ })
|
76
90
|
end
|
77
91
|
end
|
78
92
|
|
@@ -85,14 +99,15 @@ module AbstractController
|
|
85
99
|
|
86
100
|
# Returns the full controller name, underscored, without the ending Controller.
|
87
101
|
# For instance, MyApp::MyPostsController would return "my_app/my_posts" for
|
88
|
-
#
|
102
|
+
# controller_path.
|
89
103
|
#
|
90
104
|
# ==== Returns
|
91
|
-
# * <tt>
|
105
|
+
# * <tt>String</tt>
|
92
106
|
def controller_path
|
93
107
|
@controller_path ||= name.sub(/Controller$/, '').underscore unless anonymous?
|
94
108
|
end
|
95
109
|
|
110
|
+
# Refresh the cached action_methods when a new action_method is added.
|
96
111
|
def method_added(name)
|
97
112
|
super
|
98
113
|
clear_action_methods!
|
@@ -112,7 +127,7 @@ module AbstractController
|
|
112
127
|
def process(action, *args)
|
113
128
|
@_action_name = action_name = action.to_s
|
114
129
|
|
115
|
-
unless action_name =
|
130
|
+
unless action_name = method_for_action(action_name)
|
116
131
|
raise ActionNotFound, "The action '#{action}' could not be found for #{self.class.name}"
|
117
132
|
end
|
118
133
|
|
@@ -126,6 +141,7 @@ module AbstractController
|
|
126
141
|
self.class.controller_path
|
127
142
|
end
|
128
143
|
|
144
|
+
# Delegates to the class' #action_methods
|
129
145
|
def action_methods
|
130
146
|
self.class.action_methods
|
131
147
|
end
|
@@ -135,10 +151,16 @@ module AbstractController
|
|
135
151
|
#
|
136
152
|
# Notice that <tt>action_methods.include?("foo")</tt> may return
|
137
153
|
# false and <tt>available_action?("foo")</tt> returns true because
|
138
|
-
#
|
154
|
+
# this method considers actions that are also available
|
139
155
|
# through other means, for example, implicit render ones.
|
156
|
+
#
|
157
|
+
# ==== Parameters
|
158
|
+
# * <tt>action_name</tt> - The name of an action to be tested
|
159
|
+
#
|
160
|
+
# ==== Returns
|
161
|
+
# * <tt>TrueClass</tt>, <tt>FalseClass</tt>
|
140
162
|
def available_action?(action_name)
|
141
|
-
|
163
|
+
method_for_action(action_name).present?
|
142
164
|
end
|
143
165
|
|
144
166
|
private
|
@@ -181,23 +203,6 @@ module AbstractController
|
|
181
203
|
action_missing(@_action_name, *args)
|
182
204
|
end
|
183
205
|
|
184
|
-
# Takes an action name and returns the name of the method that will
|
185
|
-
# handle the action.
|
186
|
-
#
|
187
|
-
# It checks if the action name is valid and returns false otherwise.
|
188
|
-
#
|
189
|
-
# See method_for_action for more information.
|
190
|
-
#
|
191
|
-
# ==== Parameters
|
192
|
-
# * <tt>action_name</tt> - An action name to find a method name for
|
193
|
-
#
|
194
|
-
# ==== Returns
|
195
|
-
# * <tt>string</tt> - The name of the method that handles the action
|
196
|
-
# * false - No valid method name could be found. Raise ActionNotFound.
|
197
|
-
def _find_action_name(action_name)
|
198
|
-
_valid_action_name?(action_name) && method_for_action(action_name)
|
199
|
-
end
|
200
|
-
|
201
206
|
# Takes an action name and returns the name of the method that will
|
202
207
|
# handle the action. In normal cases, this method returns the same
|
203
208
|
# name as it receives. By default, if #method_for_action receives
|
@@ -220,16 +225,13 @@ module AbstractController
|
|
220
225
|
#
|
221
226
|
# ==== Returns
|
222
227
|
# * <tt>string</tt> - The name of the method that handles the action
|
223
|
-
# * <tt>nil</tt> - No method name could be found.
|
228
|
+
# * <tt>nil</tt> - No method name could be found. Raise ActionNotFound.
|
224
229
|
def method_for_action(action_name)
|
225
|
-
if action_method?(action_name)
|
226
|
-
|
230
|
+
if action_method?(action_name)
|
231
|
+
action_name
|
232
|
+
elsif respond_to?(:action_missing, true)
|
233
|
+
"_handle_action_missing"
|
227
234
|
end
|
228
235
|
end
|
229
|
-
|
230
|
-
# Checks if the action name is valid and returns false otherwise.
|
231
|
-
def _valid_action_name?(action_name)
|
232
|
-
action_name.to_s !~ Regexp.new(File::SEPARATOR)
|
233
|
-
end
|
234
236
|
end
|
235
237
|
end
|