Skip to content

Commit 6abeba5

Browse files
committed
Merge branch 'master' of git://github.com/rails/rails
2 parents 6a30a96 + ea8077c commit 6abeba5

File tree

26 files changed

+505
-378
lines changed

26 files changed

+505
-378
lines changed

actionpack/lib/action_controller/test_process.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def initialize(env = {})
1313

1414
@query_parameters = {}
1515
@session = TestSession.new
16+
@session_options ||= {}
1617

1718
initialize_default_values
1819
initialize_containers
@@ -110,6 +111,7 @@ def assign_parameters(controller_path, action, parameters)
110111
end
111112

112113
def recycle!
114+
@env["action_controller.request.request_parameters"] = {}
113115
self.query_parameters = {}
114116
self.path_parameters = {}
115117
@headers, @request_method, @accepts, @content_type = nil, nil, nil, nil

actionpack/lib/action_view/helpers/form_helper.rb

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -628,20 +628,23 @@ def text_area(object_name, method, options = {})
628628
#
629629
# The HTML specification says unchecked check boxes are not successful, and
630630
# thus web browsers do not send them. Unfortunately this introduces a gotcha:
631-
# if an Invoice model has a +paid+ flag, and in the form that edits a paid
631+
# if an +Invoice+ model has a +paid+ flag, and in the form that edits a paid
632632
# invoice the user unchecks its check box, no +paid+ parameter is sent. So,
633633
# any mass-assignment idiom like
634634
#
635635
# @invoice.update_attributes(params[:invoice])
636636
#
637637
# wouldn't update the flag.
638638
#
639-
# To prevent this the helper generates a hidden field with the same name as
640-
# the checkbox after the very check box. So, the client either sends only the
641-
# hidden field (representing the check box is unchecked), or both fields.
642-
# Since the HTML specification says key/value pairs have to be sent in the
643-
# same order they appear in the form and Rails parameters extraction always
644-
# gets the first occurrence of any given key, that works in ordinary forms.
639+
# To prevent this the helper generates an auxiliary hidden field before
640+
# the very check box. The hidden field has the same name and its
641+
# attributes mimick an unchecked check box.
642+
#
643+
# This way, the client either sends only the hidden field (representing
644+
# the check box is unchecked), or both fields. Since the HTML specification
645+
# says key/value pairs have to be sent in the same order they appear in the
646+
# form, and parameters extraction gets the last occurrence of any repeated
647+
# key in the query string, that works for ordinary forms.
645648
#
646649
# Unfortunately that workaround does not work when the check box goes
647650
# within an array-like parameter, as in
@@ -652,22 +655,26 @@ def text_area(object_name, method, options = {})
652655
# <% end %>
653656
#
654657
# because parameter name repetition is precisely what Rails seeks to distinguish
655-
# the elements of the array.
658+
# the elements of the array. For each item with a checked check box you
659+
# get an extra ghost item with only that attribute, assigned to "0".
660+
#
661+
# In that case it is preferable to either use +check_box_tag+ or to use
662+
# hashes instead of arrays.
656663
#
657664
# ==== Examples
658665
# # Let's say that @post.validated? is 1:
659666
# check_box("post", "validated")
660-
# # => <input type="checkbox" id="post_validated" name="post[validated]" value="1" />
661-
# # <input name="post[validated]" type="hidden" value="0" />
667+
# # => <input name="post[validated]" type="hidden" value="0" />
668+
# # <input type="checkbox" id="post_validated" name="post[validated]" value="1" />
662669
#
663670
# # Let's say that @puppy.gooddog is "no":
664671
# check_box("puppy", "gooddog", {}, "yes", "no")
665-
# # => <input type="checkbox" id="puppy_gooddog" name="puppy[gooddog]" value="yes" />
666-
# # <input name="puppy[gooddog]" type="hidden" value="no" />
672+
# # => <input name="puppy[gooddog]" type="hidden" value="no" />
673+
# # <input type="checkbox" id="puppy_gooddog" name="puppy[gooddog]" value="yes" />
667674
#
668675
# check_box("eula", "accepted", { :class => 'eula_check' }, "yes", "no")
669-
# # => <input type="checkbox" class="eula_check" id="eula_accepted" name="eula[accepted]" value="yes" />
670-
# # <input name="eula[accepted]" type="hidden" value="no" />
676+
# # => <input name="eula[accepted]" type="hidden" value="no" />
677+
# # <input type="checkbox" class="eula_check" id="eula_accepted" name="eula[accepted]" value="yes" />
671678
#
672679
def check_box(object_name, method, options = {}, checked_value = "1", unchecked_value = "0")
673680
InstanceTag.new(object_name, method, self, options.delete(:object)).to_check_box_tag(options, checked_value, unchecked_value)

actionpack/lib/action_view/helpers/text_helper.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ def simple_format(text, html_options={})
324324

325325
# Turns all URLs and e-mail addresses into clickable links. The <tt>:link</tt> option
326326
# will limit what should be linked. You can add HTML attributes to the links using
327-
# <tt>:href_options</tt>. Possible values for <tt>:link</tt> are <tt>:all</tt> (default),
327+
# <tt>:html</tt>. Possible values for <tt>:link</tt> are <tt>:all</tt> (default),
328328
# <tt>:email_addresses</tt>, and <tt>:urls</tt>. If a block is given, each URL and
329329
# e-mail address is yielded and the result is used as the link text.
330330
#
@@ -341,7 +341,7 @@ def simple_format(text, html_options={})
341341
# # => "Visit http://www.loudthinking.com/ or e-mail <a href=\"mailto:[email protected]\">[email protected]</a>"
342342
#
343343
# post_body = "Welcome to my new blog at http://www.myblog.com/. Please e-mail me at [email protected]."
344-
# auto_link(post_body, :href_options => { :target => '_blank' }) do |text|
344+
# auto_link(post_body, :html => { :target => '_blank' }) do |text|
345345
# truncate(text, 15)
346346
# end
347347
# # => "Welcome to my new blog at <a href=\"http://www.myblog.com/\" target=\"_blank\">http://www.m...</a>.
@@ -359,7 +359,7 @@ def simple_format(text, html_options={})
359359
# auto_link(post_body, :all, :target => "_blank") # => Once upon\na time
360360
# # => "Welcome to my new blog at <a href=\"http://www.myblog.com/\" target=\"_blank\">http://www.myblog.com</a>.
361361
# Please e-mail me at <a href=\"mailto:[email protected]\">[email protected]</a>."
362-
def auto_link(text, *args, &block)#link = :all, href_options = {}, &block)
362+
def auto_link(text, *args, &block)#link = :all, html = {}, &block)
363363
return '' if text.blank?
364364

365365
options = args.size == 2 ? {} : args.extract_options! # this is necessary because the old auto_link API has a Hash as its last parameter

actionpack/lib/action_view/paths.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def find_template(original_template_path, format = nil, html_fallback = true)
6161
end
6262
end
6363

64-
return Template.new(original_template_path, original_template_path.to_s =~ /\A\// ? "" : ".") if File.file?(original_template_path)
64+
return Template.new(original_template_path) if File.file?(original_template_path)
6565

6666
raise MissingTemplate.new(self, original_template_path, format)
6767
end

actionpack/lib/action_view/template.rb

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,8 @@ def self.exempt_from_layout(*extensions)
107107
attr_accessor :locale, :name, :format, :extension
108108
delegate :to_s, :to => :path
109109

110-
def initialize(template_path, load_path)
111-
@template_path = template_path.dup
112-
@load_path, @filename = load_path, File.join(load_path, template_path)
110+
def initialize(template_path, load_path = nil)
111+
@template_path, @load_path = template_path.dup, load_path
113112
@base_path, @name, @locale, @format, @extension = split(template_path)
114113
@base_path.to_s.gsub!(/\/$/, '') # Push to split method
115114

@@ -180,6 +179,12 @@ def exempt_from_layout?
180179
@@exempt_from_layout.any? { |exempted| path =~ exempted }
181180
end
182181

182+
def filename
183+
# no load_path means this is an "absolute pathed" template
184+
load_path ? File.join(load_path, template_path) : template_path
185+
end
186+
memoize :filename
187+
183188
def source
184189
File.read(filename)
185190
end
@@ -212,46 +217,30 @@ def valid_extension?(extension)
212217
end
213218

214219
def valid_locale?(locale)
215-
I18n.available_locales.include?(locale.to_sym)
220+
locale && I18n.available_locales.include?(locale.to_sym)
216221
end
217222

218223
# Returns file split into an array
219224
# [base_path, name, locale, format, extension]
220225
def split(file)
221226
if m = file.to_s.match(/^(.*\/)?([^\.]+)\.(.*)$/)
222-
base_path = m[1]
223-
name = m[2]
224-
extensions = m[3]
225-
else
226-
return
227+
[m[1], m[2], *parse_extensions(m[3])]
227228
end
229+
end
228230

229-
locale = nil
230-
format = nil
231-
extension = nil
232-
233-
if m = extensions.split(".")
234-
if valid_locale?(m[0]) && m[1] && valid_extension?(m[2]) # All three
235-
locale = m[0]
236-
format = m[1]
237-
extension = m[2]
238-
elsif m[0] && m[1] && valid_extension?(m[2]) # Multipart formats
239-
format = "#{m[0]}.#{m[1]}"
240-
extension = m[2]
241-
elsif valid_locale?(m[0]) && valid_extension?(m[1]) # locale and extension
242-
locale = m[0]
243-
extension = m[1]
244-
elsif valid_extension?(m[1]) # format and extension
245-
format = m[0]
246-
extension = m[1]
247-
elsif valid_extension?(m[0]) # Just extension
248-
extension = m[0]
249-
else # No extension
250-
format = m[0]
251-
end
231+
# returns parsed extensions as an array
232+
# [locale, format, extension]
233+
def parse_extensions(extensions)
234+
exts = extensions.split(".")
235+
236+
if extension = valid_extension?(exts.last) && exts.pop || nil
237+
locale = valid_locale?(exts.first) && exts.shift || nil
238+
format = exts.join('.') if exts.any? # join('.') is needed for multipart templates
239+
else # no extension, just format
240+
format = exts.last
252241
end
253242

254-
[base_path, name, locale, format, extension]
243+
[locale, format, extension]
255244
end
256245
end
257246
end

0 commit comments

Comments
 (0)