actionpack 1.9.1 → 1.10.1
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.
- data/CHANGELOG +237 -0
- data/README +12 -12
- data/lib/action_controller.rb +17 -12
- data/lib/action_controller/assertions.rb +119 -67
- data/lib/action_controller/base.rb +184 -102
- data/lib/action_controller/benchmarking.rb +35 -6
- data/lib/action_controller/caching.rb +115 -58
- data/lib/action_controller/cgi_ext/cgi_methods.rb +54 -21
- data/lib/action_controller/cgi_ext/cookie_performance_fix.rb +39 -35
- data/lib/action_controller/cgi_ext/raw_post_data_fix.rb +34 -21
- data/lib/action_controller/cgi_process.rb +23 -20
- data/lib/action_controller/components.rb +11 -2
- data/lib/action_controller/dependencies.rb +0 -5
- data/lib/action_controller/deprecated_redirects.rb +17 -0
- data/lib/action_controller/filters.rb +13 -9
- data/lib/action_controller/flash.rb +7 -7
- data/lib/action_controller/helpers.rb +1 -14
- data/lib/action_controller/layout.rb +40 -29
- data/lib/action_controller/macros/auto_complete.rb +52 -0
- data/lib/action_controller/macros/in_place_editing.rb +32 -0
- data/lib/action_controller/pagination.rb +44 -28
- data/lib/action_controller/request.rb +54 -40
- data/lib/action_controller/rescue.rb +8 -6
- data/lib/action_controller/routing.rb +77 -28
- data/lib/action_controller/scaffolding.rb +10 -14
- data/lib/action_controller/session/active_record_store.rb +36 -7
- data/lib/action_controller/session_management.rb +126 -0
- data/lib/action_controller/streaming.rb +14 -5
- data/lib/action_controller/templates/rescues/_request_and_response.rhtml +1 -1
- data/lib/action_controller/templates/rescues/_trace.rhtml +24 -0
- data/lib/action_controller/templates/rescues/diagnostics.rhtml +2 -13
- data/lib/action_controller/templates/rescues/template_error.rhtml +4 -2
- data/lib/action_controller/templates/scaffolds/list.rhtml +1 -1
- data/lib/action_controller/test_process.rb +35 -17
- data/lib/action_controller/upload_progress.rb +52 -0
- data/lib/action_controller/url_rewriter.rb +21 -16
- data/lib/action_controller/vendor/html-scanner/html/document.rb +2 -2
- data/lib/action_controller/vendor/html-scanner/html/node.rb +30 -3
- data/lib/action_pack/version.rb +9 -0
- data/lib/action_view.rb +1 -1
- data/lib/action_view/base.rb +204 -60
- data/lib/action_view/compiled_templates.rb +70 -0
- data/lib/action_view/helpers/active_record_helper.rb +7 -3
- data/lib/action_view/helpers/asset_tag_helper.rb +22 -12
- data/lib/action_view/helpers/capture_helper.rb +2 -10
- data/lib/action_view/helpers/date_helper.rb +21 -13
- data/lib/action_view/helpers/form_helper.rb +14 -10
- data/lib/action_view/helpers/form_options_helper.rb +4 -4
- data/lib/action_view/helpers/form_tag_helper.rb +59 -25
- data/lib/action_view/helpers/java_script_macros_helper.rb +188 -0
- data/lib/action_view/helpers/javascript_helper.rb +68 -133
- data/lib/action_view/helpers/javascripts/controls.js +427 -165
- data/lib/action_view/helpers/javascripts/dragdrop.js +256 -277
- data/lib/action_view/helpers/javascripts/effects.js +766 -277
- data/lib/action_view/helpers/javascripts/prototype.js +906 -218
- data/lib/action_view/helpers/javascripts/slider.js +258 -0
- data/lib/action_view/helpers/number_helper.rb +4 -3
- data/lib/action_view/helpers/pagination_helper.rb +42 -27
- data/lib/action_view/helpers/tag_helper.rb +25 -11
- data/lib/action_view/helpers/text_helper.rb +119 -13
- data/lib/action_view/helpers/upload_progress_helper.rb +2 -2
- data/lib/action_view/helpers/url_helper.rb +68 -21
- data/lib/action_view/partials.rb +17 -6
- data/lib/action_view/template_error.rb +19 -24
- data/rakefile +4 -3
- data/test/abstract_unit.rb +2 -1
- data/test/controller/action_pack_assertions_test.rb +62 -2
- data/test/controller/active_record_assertions_test.rb +5 -6
- data/test/controller/active_record_store_test.rb +23 -1
- data/test/controller/addresses_render_test.rb +4 -0
- data/test/controller/{base_tests.rb → base_test.rb} +4 -3
- data/test/controller/benchmark_test.rb +36 -0
- data/test/controller/caching_filestore.rb +22 -40
- data/test/controller/capture_test.rb +10 -1
- data/test/controller/cgi_test.rb +145 -23
- data/test/controller/components_test.rb +50 -0
- data/test/controller/custom_handler_test.rb +3 -3
- data/test/controller/fake_controllers.rb +24 -0
- data/test/controller/filters_test.rb +6 -6
- data/test/controller/flash_test.rb +6 -6
- data/test/controller/fragment_store_setting_test.rb +45 -0
- data/test/controller/helper_test.rb +1 -3
- data/test/controller/new_render_test.rb +119 -7
- data/test/controller/redirect_test.rb +11 -1
- data/test/controller/render_test.rb +34 -1
- data/test/controller/request_test.rb +14 -5
- data/test/controller/routing_test.rb +238 -42
- data/test/controller/send_file_test.rb +11 -10
- data/test/controller/session_management_test.rb +94 -0
- data/test/controller/test_test.rb +194 -5
- data/test/controller/url_rewriter_test.rb +46 -0
- data/test/fixtures/layouts/talk_from_action.rhtml +2 -0
- data/test/fixtures/layouts/yield.rhtml +2 -0
- data/test/fixtures/multipart/binary_file +0 -0
- data/test/fixtures/multipart/large_text_file +10 -0
- data/test/fixtures/multipart/mixed_files +0 -0
- data/test/fixtures/multipart/single_parameter +5 -0
- data/test/fixtures/multipart/text_file +10 -0
- data/test/fixtures/test/_customer_greeting.rhtml +1 -0
- data/test/fixtures/test/_hash_object.rhtml +1 -0
- data/test/fixtures/test/_person.rhtml +2 -0
- data/test/fixtures/test/action_talk_to_layout.rhtml +2 -0
- data/test/fixtures/test/content_for.rhtml +2 -0
- data/test/fixtures/test/potential_conflicts.rhtml +4 -0
- data/test/template/active_record_helper_test.rb +15 -8
- data/test/template/asset_tag_helper_test.rb +40 -16
- data/test/template/compiled_templates_tests.rb +63 -0
- data/test/template/date_helper_test.rb +80 -4
- data/test/template/form_helper_test.rb +48 -42
- data/test/template/form_options_helper_test.rb +40 -40
- data/test/template/form_tag_helper_test.rb +21 -15
- data/test/template/java_script_macros_helper_test.rb +56 -0
- data/test/template/javascript_helper_test.rb +70 -47
- data/test/template/number_helper_test.rb +2 -0
- data/test/template/tag_helper_test.rb +9 -0
- data/test/template/text_helper_test.rb +146 -1
- data/test/template/upload_progress_helper_testx.rb +11 -147
- data/test/template/url_helper_test.rb +90 -22
- data/test/testing_sandbox.rb +26 -0
- metadata +37 -7
- data/lib/action_controller/auto_complete.rb +0 -47
- data/lib/action_controller/deprecated_renders_and_redirects.rb +0 -76
- data/lib/action_controller/session.rb +0 -14
@@ -23,28 +23,32 @@ class CGI #:nodoc:
|
|
23
23
|
# servers.
|
24
24
|
#
|
25
25
|
# These keywords correspond to attributes of the cookie object.
|
26
|
-
def initialize(name =
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
def initialize(name = '', *value)
|
27
|
+
if name.kind_of?(String)
|
28
|
+
@name = name
|
29
|
+
@value = Array(value)
|
30
|
+
@domain = nil
|
31
|
+
@expires = nil
|
32
|
+
@secure = false
|
33
|
+
@path = nil
|
34
|
+
else
|
35
|
+
@name = name['name']
|
36
|
+
@value = Array(name['value'])
|
37
|
+
@domain = name['domain']
|
38
|
+
@expires = name['expires']
|
39
|
+
@secure = name['secure'] || false
|
40
|
+
@path = name['path']
|
41
|
+
end
|
42
|
+
|
43
|
+
unless @name
|
33
44
|
raise ArgumentError, "`name' required"
|
34
45
|
end
|
35
46
|
|
36
|
-
@name = options["name"]
|
37
|
-
@value = Array(options["value"])
|
38
47
|
# simple support for IE
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
%r|^(.*/)|.match(ENV["SCRIPT_NAME"])
|
43
|
-
@path = ($1 or "")
|
48
|
+
unless @path
|
49
|
+
%r|^(.*/)|.match(ENV['SCRIPT_NAME'])
|
50
|
+
@path = ($1 or '')
|
44
51
|
end
|
45
|
-
@domain = options["domain"]
|
46
|
-
@expires = options["expires"]
|
47
|
-
@secure = options["secure"] == true ? true : false
|
48
52
|
|
49
53
|
super(@value)
|
50
54
|
end
|
@@ -67,28 +71,28 @@ class CGI #:nodoc:
|
|
67
71
|
# Convert the Cookie to its string representation.
|
68
72
|
def to_s
|
69
73
|
buf = ""
|
70
|
-
buf
|
74
|
+
buf << @name << '='
|
71
75
|
|
72
76
|
if @value.kind_of?(String)
|
73
|
-
buf
|
77
|
+
buf << CGI::escape(@value)
|
74
78
|
else
|
75
|
-
buf
|
79
|
+
buf << @value.collect{|v| CGI::escape(v) }.join("&")
|
76
80
|
end
|
77
81
|
|
78
82
|
if @domain
|
79
|
-
buf
|
83
|
+
buf << '; domain=' << @domain
|
80
84
|
end
|
81
85
|
|
82
86
|
if @path
|
83
|
-
buf
|
87
|
+
buf << '; path=' << @path
|
84
88
|
end
|
85
89
|
|
86
90
|
if @expires
|
87
|
-
buf
|
91
|
+
buf << '; expires=' << CGI::rfc1123_date(@expires)
|
88
92
|
end
|
89
93
|
|
90
94
|
if @secure == true
|
91
|
-
buf
|
95
|
+
buf << '; secure'
|
92
96
|
end
|
93
97
|
|
94
98
|
buf
|
@@ -102,20 +106,20 @@ class CGI #:nodoc:
|
|
102
106
|
#
|
103
107
|
def self.parse(raw_cookie)
|
104
108
|
cookies = Hash.new([])
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
109
|
+
|
110
|
+
if raw_cookie
|
111
|
+
raw_cookie.split(/; /).each do |pairs|
|
112
|
+
name, values = pairs.split('=',2)
|
113
|
+
next unless name and values
|
114
|
+
name = CGI::unescape(name)
|
115
|
+
values = values.split('&').collect!{|v| CGI::unescape(v) }
|
116
|
+
unless cookies.has_key?(name)
|
117
|
+
cookies[name] = new(name, *values)
|
118
|
+
end
|
115
119
|
end
|
116
120
|
end
|
117
121
|
|
118
122
|
cookies
|
119
123
|
end
|
120
124
|
end # class Cookie
|
121
|
-
end
|
125
|
+
end
|
@@ -6,14 +6,21 @@ class CGI #:nodoc:
|
|
6
6
|
# Handles multipart forms (in particular, forms that involve file uploads).
|
7
7
|
# Reads query parameters in the @params field, and cookies into @cookies.
|
8
8
|
def initialize_query()
|
9
|
-
@cookies = CGI::Cookie::parse(
|
9
|
+
@cookies = CGI::Cookie::parse(env_table['HTTP_COOKIE'] || env_table['COOKIE'])
|
10
10
|
|
11
|
-
|
11
|
+
#fix some strange request environments
|
12
|
+
if method = env_table['REQUEST_METHOD']
|
13
|
+
method = method.to_s.downcase.intern
|
14
|
+
else
|
15
|
+
method = :get
|
16
|
+
end
|
17
|
+
|
18
|
+
if method == :post && (boundary = multipart_form_boundary)
|
12
19
|
@multipart = true
|
13
20
|
@params = read_multipart(boundary, Integer(env_table['CONTENT_LENGTH']))
|
14
21
|
else
|
15
22
|
@multipart = false
|
16
|
-
@params = CGI::parse(read_query_params || "")
|
23
|
+
@params = CGI::parse(read_query_params(method) || "")
|
17
24
|
end
|
18
25
|
end
|
19
26
|
|
@@ -22,37 +29,43 @@ class CGI #:nodoc:
|
|
22
29
|
MULTIPART_FORM_BOUNDARY_RE = %r|\Amultipart/form-data.*boundary=\"?([^\";,]+)\"?|n #"
|
23
30
|
end
|
24
31
|
|
25
|
-
def multipart_form_boundary
|
26
|
-
|
27
|
-
MULTIPART_FORM_BOUNDARY_RE.match(env_table['CONTENT_TYPE']).to_a.pop
|
28
|
-
end
|
32
|
+
def multipart_form_boundary
|
33
|
+
MULTIPART_FORM_BOUNDARY_RE.match(env_table['CONTENT_TYPE']).to_a.pop
|
29
34
|
end
|
30
35
|
|
31
|
-
|
32
|
-
|
36
|
+
if defined? MOD_RUBY
|
37
|
+
def read_params_from_query
|
33
38
|
Apache::request.args || ''
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
39
|
+
end
|
40
|
+
else
|
41
|
+
def read_params_from_query
|
42
|
+
# fixes CGI querystring parsing for lighttpd
|
43
|
+
env_qs = env_table['QUERY_STRING']
|
44
|
+
if env_qs.blank? && !(uri = env_table['REQUEST_URI']).blank?
|
45
|
+
uri.split('?', 2)[1] || ''
|
46
|
+
else
|
47
|
+
env_qs
|
38
48
|
end
|
39
|
-
env_table['QUERY_STRING']
|
40
49
|
end
|
41
50
|
end
|
42
51
|
|
43
52
|
def read_params_from_post
|
44
53
|
stdinput.binmode if stdinput.respond_to?(:binmode)
|
45
54
|
content = stdinput.read(Integer(env_table['CONTENT_LENGTH'])) || ''
|
46
|
-
|
55
|
+
# fix for Safari Ajax postings that always append \000
|
56
|
+
content.chop! if content[-1] == 0
|
57
|
+
env_table['RAW_POST_DATA'] = content.freeze
|
47
58
|
end
|
48
59
|
|
49
|
-
def read_query_params
|
50
|
-
case
|
51
|
-
when
|
52
|
-
|
53
|
-
when
|
60
|
+
def read_query_params(method)
|
61
|
+
case method
|
62
|
+
when :get
|
63
|
+
read_params_from_query
|
64
|
+
when :post, :put
|
54
65
|
read_params_from_post
|
55
|
-
|
66
|
+
when :cmd
|
67
|
+
read_from_cmdline
|
68
|
+
else # when :head, :delete, :options
|
56
69
|
read_params_from_query
|
57
70
|
end
|
58
71
|
end
|
@@ -1,11 +1,6 @@
|
|
1
1
|
require 'action_controller/cgi_ext/cgi_ext'
|
2
2
|
require 'action_controller/cgi_ext/cookie_performance_fix'
|
3
3
|
require 'action_controller/cgi_ext/raw_post_data_fix'
|
4
|
-
require 'action_controller/session/drb_store'
|
5
|
-
require 'action_controller/session/mem_cache_store'
|
6
|
-
if Object.const_defined?(:ActiveRecord)
|
7
|
-
require 'action_controller/session/active_record_store'
|
8
|
-
end
|
9
4
|
|
10
5
|
module ActionController #:nodoc:
|
11
6
|
class Base
|
@@ -37,7 +32,7 @@ module ActionController #:nodoc:
|
|
37
32
|
end
|
38
33
|
|
39
34
|
class CgiRequest < AbstractRequest #:nodoc:
|
40
|
-
attr_accessor :cgi
|
35
|
+
attr_accessor :cgi, :session_options
|
41
36
|
|
42
37
|
DEFAULT_SESSION_OPTIONS = {
|
43
38
|
:database_manager => CGI::Session::PStore,
|
@@ -52,19 +47,19 @@ module ActionController #:nodoc:
|
|
52
47
|
end
|
53
48
|
|
54
49
|
def query_string
|
55
|
-
|
56
|
-
|
57
|
-
|
50
|
+
if (qs = @cgi.query_string) && !qs.empty?
|
51
|
+
qs
|
52
|
+
elsif uri = env['REQUEST_URI']
|
53
|
+
parts = uri.split('?')
|
54
|
+
parts.shift
|
55
|
+
parts.join('?')
|
58
56
|
else
|
59
|
-
|
60
|
-
end
|
61
|
-
parts.shift
|
62
|
-
return parts.join('?')
|
57
|
+
env['QUERY_STRING'] || ''
|
58
|
+
end
|
63
59
|
end
|
64
60
|
|
65
61
|
def query_parameters
|
66
|
-
qs = self.query_string
|
67
|
-
qs.empty? ? {} : CGIMethods.parse_query_parameters(query_string)
|
62
|
+
(qs = self.query_string).empty? ? {} : CGIMethods.parse_query_parameters(qs)
|
68
63
|
end
|
69
64
|
|
70
65
|
def request_parameters
|
@@ -84,7 +79,15 @@ module ActionController #:nodoc:
|
|
84
79
|
end
|
85
80
|
|
86
81
|
def host
|
87
|
-
env["HTTP_X_FORWARDED_HOST"] || @cgi.host.to_s.split(":").first
|
82
|
+
env["HTTP_X_FORWARDED_HOST"] || ($1 if env['HTTP_HOST'] && /^(.*):\d+$/ =~ env['HTTP_HOST']) || @cgi.host.to_s.split(":").first || ''
|
83
|
+
end
|
84
|
+
|
85
|
+
def port
|
86
|
+
env["HTTP_X_FORWARDED_HOST"] ? standard_port : (port_from_http_host || super)
|
87
|
+
end
|
88
|
+
|
89
|
+
def port_from_http_host
|
90
|
+
$1.to_i if env['HTTP_HOST'] && /:(\d+)$/ =~ env['HTTP_HOST']
|
88
91
|
end
|
89
92
|
|
90
93
|
def session
|
@@ -115,7 +118,7 @@ module ActionController #:nodoc:
|
|
115
118
|
end
|
116
119
|
|
117
120
|
def reset_session
|
118
|
-
@session.delete
|
121
|
+
@session.delete if CGI::Session === @session
|
119
122
|
@session = (@session_options == false ? {} : new_session)
|
120
123
|
end
|
121
124
|
|
@@ -125,11 +128,11 @@ module ActionController #:nodoc:
|
|
125
128
|
|
126
129
|
private
|
127
130
|
def new_session
|
128
|
-
CGI::Session.new(@cgi, session_options_with_string_keys.
|
131
|
+
CGI::Session.new(@cgi, session_options_with_string_keys.update("new_session" => true))
|
129
132
|
end
|
130
133
|
|
131
134
|
def session_options_with_string_keys
|
132
|
-
DEFAULT_SESSION_OPTIONS.merge(@session_options).inject({}) { |options,
|
135
|
+
DEFAULT_SESSION_OPTIONS.merge(@session_options).inject({}) { |options, (k,v)| options[k.to_s] = v; options }
|
133
136
|
end
|
134
137
|
end
|
135
138
|
|
@@ -150,7 +153,7 @@ module ActionController #:nodoc:
|
|
150
153
|
if @cgi.send(:env_table)['REQUEST_METHOD'] == 'HEAD'
|
151
154
|
return
|
152
155
|
elsif @body.respond_to?(:call)
|
153
|
-
@body.call(self)
|
156
|
+
@body.call(self, output)
|
154
157
|
else
|
155
158
|
output.write(@body)
|
156
159
|
end
|
@@ -38,12 +38,21 @@ module ActionController #:nodoc:
|
|
38
38
|
|
39
39
|
# Returns the component response as a string
|
40
40
|
def render_component_as_string(options) #:doc:
|
41
|
-
component_logging(options)
|
41
|
+
component_logging(options) do
|
42
|
+
response = component_response(options, false)
|
43
|
+
unless response.redirected_to.nil?
|
44
|
+
render_component_as_string response.redirected_to
|
45
|
+
else
|
46
|
+
response.body
|
47
|
+
end
|
48
|
+
end
|
42
49
|
end
|
43
50
|
|
44
51
|
private
|
45
52
|
def component_response(options, reuse_response = true)
|
46
|
-
component_class(options)
|
53
|
+
c = component_class(options)
|
54
|
+
c.after_filter {|c| flash.keep }
|
55
|
+
c.process(request_for_component(options), reuse_response ? @response : response_for_component)
|
47
56
|
end
|
48
57
|
|
49
58
|
def component_class(options)
|
@@ -2,7 +2,6 @@ module ActionController #:nodoc:
|
|
2
2
|
module Dependencies #:nodoc:
|
3
3
|
def self.append_features(base)
|
4
4
|
super
|
5
|
-
base.class_eval { class << self; alias_method :inherited_without_model, :inherited; end }
|
6
5
|
base.extend(ClassMethods)
|
7
6
|
end
|
8
7
|
|
@@ -79,10 +78,6 @@ module ActionController #:nodoc:
|
|
79
78
|
end
|
80
79
|
end
|
81
80
|
end
|
82
|
-
|
83
|
-
def inherited(child)
|
84
|
-
inherited_without_model(child)
|
85
|
-
end
|
86
81
|
end
|
87
82
|
end
|
88
83
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module ActionController
|
2
|
+
class Base
|
3
|
+
protected
|
4
|
+
# Deprecated in favor of calling redirect_to directly with the path.
|
5
|
+
def redirect_to_path(path)
|
6
|
+
redirect_to(path)
|
7
|
+
end
|
8
|
+
|
9
|
+
# Deprecated in favor of calling redirect_to directly with the url. If the resource has moved permanently, it's possible to pass
|
10
|
+
# true as the second parameter and the browser will get "301 Moved Permanently" instead of "302 Found". This can also be done through
|
11
|
+
# just setting the headers["Status"] to "301 Moved Permanently" before using the redirect_to.
|
12
|
+
def redirect_to_url(url, permanently = false)
|
13
|
+
headers["Status"] = "301 Moved Permanently" if permanently
|
14
|
+
redirect_to(url)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -157,7 +157,7 @@ module ActionController #:nodoc:
|
|
157
157
|
conditions = extract_conditions!(filters)
|
158
158
|
filters << block if block_given?
|
159
159
|
add_action_conditions(filters, conditions)
|
160
|
-
append_filter_to_chain(
|
160
|
+
append_filter_to_chain('before', filters)
|
161
161
|
end
|
162
162
|
|
163
163
|
# The passed <tt>filters</tt> will be prepended to the array of filters that's run _before_ actions
|
@@ -166,7 +166,7 @@ module ActionController #:nodoc:
|
|
166
166
|
conditions = extract_conditions!(filters)
|
167
167
|
filters << block if block_given?
|
168
168
|
add_action_conditions(filters, conditions)
|
169
|
-
prepend_filter_to_chain(
|
169
|
+
prepend_filter_to_chain('before', filters)
|
170
170
|
end
|
171
171
|
|
172
172
|
# Short-hand for append_before_filter since that's the most common of the two.
|
@@ -178,7 +178,7 @@ module ActionController #:nodoc:
|
|
178
178
|
conditions = extract_conditions!(filters)
|
179
179
|
filters << block if block_given?
|
180
180
|
add_action_conditions(filters, conditions)
|
181
|
-
append_filter_to_chain(
|
181
|
+
append_filter_to_chain('after', filters)
|
182
182
|
end
|
183
183
|
|
184
184
|
# The passed <tt>filters</tt> will be prepended to the array of filters that's run _after_ actions
|
@@ -272,8 +272,8 @@ module ActionController #:nodoc:
|
|
272
272
|
def add_action_conditions(filters, conditions)
|
273
273
|
return unless conditions
|
274
274
|
included, excluded = conditions[:only], conditions[:except]
|
275
|
-
write_inheritable_hash(
|
276
|
-
write_inheritable_hash(
|
275
|
+
write_inheritable_hash('included_actions', condition_hash(filters, included)) && return if included
|
276
|
+
write_inheritable_hash('excluded_actions', condition_hash(filters, excluded)) if excluded
|
277
277
|
end
|
278
278
|
|
279
279
|
def condition_hash(filters, *actions)
|
@@ -322,19 +322,23 @@ module ActionController #:nodoc:
|
|
322
322
|
else
|
323
323
|
raise(
|
324
324
|
ActionControllerError,
|
325
|
-
|
325
|
+
'Filters need to be either a symbol, proc/method, or class implementing a static filter method'
|
326
326
|
)
|
327
327
|
end
|
328
|
-
|
328
|
+
|
329
|
+
if filter_result == false
|
330
|
+
logger.info "Filter chain halted as [#{filter}] returned false" if logger
|
331
|
+
return false
|
332
|
+
end
|
329
333
|
end
|
330
334
|
end
|
331
335
|
|
332
336
|
def filter_block?(filter)
|
333
|
-
filter.respond_to?(
|
337
|
+
filter.respond_to?('call') && (filter.arity == 1 || filter.arity == -1)
|
334
338
|
end
|
335
339
|
|
336
340
|
def filter_class?(filter)
|
337
|
-
filter.respond_to?(
|
341
|
+
filter.respond_to?('filter')
|
338
342
|
end
|
339
343
|
|
340
344
|
def action_exempted?(filter)
|
@@ -1,14 +1,14 @@
|
|
1
1
|
module ActionController #:nodoc:
|
2
2
|
# The flash provides a way to pass temporary objects between actions. Anything you place in the flash will be exposed
|
3
3
|
# to the very next action and then cleared out. This is a great way of doing notices and alerts, such as a create action
|
4
|
-
# that sets <tt>flash[
|
4
|
+
# that sets <tt>flash[:notice] = "Successfully created"</tt> before redirecting to a display action that can then expose
|
5
5
|
# the flash to its template. Actually, that exposure is automatically done. Example:
|
6
6
|
#
|
7
7
|
# class WeblogController < ActionController::Base
|
8
8
|
# def create
|
9
9
|
# # save post
|
10
|
-
# flash[
|
11
|
-
# redirect_to :action => "display", :params => {
|
10
|
+
# flash[:notice] = "Successfully created post"
|
11
|
+
# redirect_to :action => "display", :params => { :id => post.id }
|
12
12
|
# end
|
13
13
|
#
|
14
14
|
# def display
|
@@ -17,7 +17,7 @@ module ActionController #:nodoc:
|
|
17
17
|
# end
|
18
18
|
#
|
19
19
|
# display.rhtml
|
20
|
-
# <% if @flash[
|
20
|
+
# <% if @flash[:notice] %><div class="notice"><%= @flash[:notice] %></div><% end %>
|
21
21
|
#
|
22
22
|
# This example just places a string in the flash, but you can put any object in there. And of course, you can put as many
|
23
23
|
# as you like at a time too. Just remember: They'll be gone by the time the next action has been performed.
|
@@ -67,7 +67,7 @@ module ActionController #:nodoc:
|
|
67
67
|
|
68
68
|
# Sets a flash that will not be available to the next action, only to the current.
|
69
69
|
#
|
70
|
-
# flash.now[
|
70
|
+
# flash.now[:message] = "Hello current action"
|
71
71
|
#
|
72
72
|
# This method enables you to use the flash as a central messaging system in your app.
|
73
73
|
# When you need to pass an object to the next action, you use the standard flash assign (<tt>[]=</tt>).
|
@@ -82,7 +82,7 @@ module ActionController #:nodoc:
|
|
82
82
|
# Keeps either the entire current flash or a specific flash entry available for the next action:
|
83
83
|
#
|
84
84
|
# flash.keep # keeps the entire flash
|
85
|
-
# flash.keep(
|
85
|
+
# flash.keep(:notice) # keeps only the "notice" entry, the rest of the flash is discarded
|
86
86
|
def keep(k=nil)
|
87
87
|
use(k, false)
|
88
88
|
end
|
@@ -90,7 +90,7 @@ module ActionController #:nodoc:
|
|
90
90
|
# Marks the entire flash or a single flash entry to be discarded by the end of the current action
|
91
91
|
#
|
92
92
|
# flash.keep # keep entire flash available for the next action
|
93
|
-
# flash.discard(
|
93
|
+
# flash.discard(:warning) # discard the "warning" entry (it'll still be available for the current action)
|
94
94
|
def discard(k=nil)
|
95
95
|
use(k)
|
96
96
|
end
|