From 23ad1eff0dab4079b7bc68f71df537fc85582d05 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 4 Feb 2010 09:29:18 -0800 Subject: Rationalize railtie dependencies: AC uses AV; AR uses AMo; and Rails always uses AS. --- actionpack/lib/action_controller/railtie.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index 9151de4462..55a5c22ac0 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -1,5 +1,6 @@ require "action_controller" require "rails" +require "action_view/railtie" module ActionController class Railtie < Rails::Railtie -- cgit v1.2.3 From 78de17cf7095af8e86d192af8d8fbe21e6f193d9 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 4 Feb 2010 14:15:16 -0800 Subject: Expose CSRF tag for UJS adapters --- actionpack/lib/action_view/helpers.rb | 2 ++ actionpack/lib/action_view/helpers/csrf_helper.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 actionpack/lib/action_view/helpers/csrf_helper.rb (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers.rb b/actionpack/lib/action_view/helpers.rb index ceb0e18d80..b4f649385a 100644 --- a/actionpack/lib/action_view/helpers.rb +++ b/actionpack/lib/action_view/helpers.rb @@ -7,6 +7,7 @@ module ActionView #:nodoc: autoload :AtomFeedHelper, 'action_view/helpers/atom_feed_helper' autoload :CacheHelper, 'action_view/helpers/cache_helper' autoload :CaptureHelper, 'action_view/helpers/capture_helper' + autoload :CsrfHelper, 'action_view/helpers/csrf_helper' autoload :DateHelper, 'action_view/helpers/date_helper' autoload :DebugHelper, 'action_view/helpers/debug_helper' autoload :FormHelper, 'action_view/helpers/form_helper' @@ -40,6 +41,7 @@ module ActionView #:nodoc: include AtomFeedHelper include CacheHelper include CaptureHelper + include CsrfHelper include DateHelper include DebugHelper include FormHelper diff --git a/actionpack/lib/action_view/helpers/csrf_helper.rb b/actionpack/lib/action_view/helpers/csrf_helper.rb new file mode 100644 index 0000000000..2d6af52180 --- /dev/null +++ b/actionpack/lib/action_view/helpers/csrf_helper.rb @@ -0,0 +1,12 @@ +module ActionView + module Helpers + module CsrfHelper + # Returns a meta tag with the request forgery protection token for forms to use. Put this in your head. + def csrf_meta_tag + if protect_against_forgery? + %().html_safe + end + end + end + end +end -- cgit v1.2.3 From 2191aa47acc0a560366c8c09fa9635602cff5f07 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 4 Feb 2010 15:26:24 -0800 Subject: Expose CSRF param name also --- actionpack/lib/action_view/helpers/csrf_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/csrf_helper.rb b/actionpack/lib/action_view/helpers/csrf_helper.rb index 2d6af52180..6f98bd4573 100644 --- a/actionpack/lib/action_view/helpers/csrf_helper.rb +++ b/actionpack/lib/action_view/helpers/csrf_helper.rb @@ -4,7 +4,7 @@ module ActionView # Returns a meta tag with the request forgery protection token for forms to use. Put this in your head. def csrf_meta_tag if protect_against_forgery? - %().html_safe + %(\n).html_safe end end end -- cgit v1.2.3 From 3062bc70eff68397a00fc652e8eee4ae8089e0a2 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 4 Feb 2010 17:45:43 -0800 Subject: HTML-escape csrf meta contents --- actionpack/lib/action_view/helpers/csrf_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/csrf_helper.rb b/actionpack/lib/action_view/helpers/csrf_helper.rb index 6f98bd4573..41c6b67f91 100644 --- a/actionpack/lib/action_view/helpers/csrf_helper.rb +++ b/actionpack/lib/action_view/helpers/csrf_helper.rb @@ -4,7 +4,7 @@ module ActionView # Returns a meta tag with the request forgery protection token for forms to use. Put this in your head. def csrf_meta_tag if protect_against_forgery? - %(\n).html_safe + %(\n).html_safe end end end -- cgit v1.2.3 From fd567785f4670b31db300324642cf2464025313e Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 5 Feb 2010 12:23:22 -0800 Subject: Make UrlWriter includable in a Module --- actionpack/lib/action_controller/metal/url_for.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/metal/url_for.rb b/actionpack/lib/action_controller/metal/url_for.rb index 51702368c1..4f3ad07be5 100644 --- a/actionpack/lib/action_controller/metal/url_for.rb +++ b/actionpack/lib/action_controller/metal/url_for.rb @@ -1,4 +1,5 @@ require 'active_support/core_ext/class/attribute' +require 'active_support/core_ext/module/attribute_accessors' module ActionController # In routes.rb one defines URL-to-controller mappings, but the reverse @@ -87,7 +88,14 @@ module ActionController included do ActionController::Routing::Routes.install_helpers(self) - class_attribute :default_url_options + + # Including in a class uses an inheritable hash. Modules get a plain hash. + if respond_to?(:class_attribute) + class_attribute :default_url_options + else + mattr_accessor :default_url_options + end + self.default_url_options = {} end -- cgit v1.2.3 From e115eb097e3e5704b9861b6f2b92cc25d23de07c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santiago=20Pastorino=20and=20Jos=C3=A9=20Ignacio=20Costa?= Date: Thu, 4 Feb 2010 21:14:46 -0200 Subject: More html_safe strings now use the safe_concat method [#3856 state:committed] Signed-off-by: Jeremy Kemper --- actionpack/lib/action_view/helpers/form_helper.rb | 2 +- actionpack/lib/action_view/helpers/form_tag_helper.rb | 6 +++--- actionpack/lib/action_view/helpers/javascript_helper.rb | 2 +- actionpack/lib/action_view/helpers/tag_helper.rb | 2 +- actionpack/lib/action_view/render/rendering.rb | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index c2ad7e9f77..238f2eb07a 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -309,7 +309,7 @@ module ActionView options[:html][:remote] = true if options.delete(:remote) - concat(form_tag(options.delete(:url) || {}, options.delete(:html) || {})) + safe_concat(form_tag(options.delete(:url) || {}, options.delete(:html) || {})) fields_for(object_name, *(args << options), &proc) safe_concat('') end diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index ba1b0bcc20..6ed6c3101b 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -441,8 +441,8 @@ module ActionView # # =>

def field_set_tag(legend = nil, options = nil, &block) content = capture(&block) - concat(tag(:fieldset, options, true)) - concat(content_tag(:legend, legend)) unless legend.blank? + safe_concat(tag(:fieldset, options, true)) + safe_concat(content_tag(:legend, legend)) unless legend.blank? concat(content) safe_concat("") end @@ -477,7 +477,7 @@ module ActionView def form_tag_in_block(html_options, &block) content = capture(&block) - concat(form_tag_html(html_options)) + safe_concat(form_tag_html(html_options)) concat(content) safe_concat("") end diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index 7dca9849c0..8fdaa8cf8d 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -86,7 +86,7 @@ module ActionView tag = content_tag(:script, javascript_cdata_section(content), html_options.merge(:type => Mime::JS)) if block_called_from_erb?(block) - concat(tag) + safe_concat(tag) else tag end diff --git a/actionpack/lib/action_view/helpers/tag_helper.rb b/actionpack/lib/action_view/helpers/tag_helper.rb index ed80e07c78..a3a8185f40 100644 --- a/actionpack/lib/action_view/helpers/tag_helper.rb +++ b/actionpack/lib/action_view/helpers/tag_helper.rb @@ -72,7 +72,7 @@ module ActionView content_tag = content_tag_string(name, capture(&block), options, escape) if block_called_from_erb?(block) - concat(content_tag) + safe_concat(content_tag) else content_tag end diff --git a/actionpack/lib/action_view/render/rendering.rb b/actionpack/lib/action_view/render/rendering.rb index 7c33f1334a..abc7c09991 100644 --- a/actionpack/lib/action_view/render/rendering.rb +++ b/actionpack/lib/action_view/render/rendering.rb @@ -19,7 +19,7 @@ module ActionView options[:locals] ||= {} if block_given? - return concat(_render_partial(options.merge(:partial => layout), &block)) + return safe_concat(_render_partial(options.merge(:partial => layout), &block)) elsif options.key?(:partial) return _render_partial(options) end -- cgit v1.2.3 From 59d8a2b4f5ffe97e01c4707278d47c29f1c66741 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 5 Feb 2010 19:01:11 -0800 Subject: Lookup the status code and rework the Completed line a bit --- actionpack/lib/action_controller/railties/subscriber.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/railties/subscriber.rb b/actionpack/lib/action_controller/railties/subscriber.rb index 1f0e6bf51a..4499e82292 100644 --- a/actionpack/lib/action_controller/railties/subscriber.rb +++ b/actionpack/lib/action_controller/railties/subscriber.rb @@ -15,9 +15,8 @@ module ActionController payload = event.payload additions = ActionController::Base.log_process_action(payload) - message = "Completed in %.0fms" % event.duration + message = "Completed #{payload[:status]} #{Rack::Utils::HTTP_STATUS_CODES[payload[:status]]} in %.0fms" % event.duration message << " (#{additions.join(" | ")})" unless additions.blank? - message << " with #{payload[:status]}" info(message) end -- cgit v1.2.3 From 4d177d46d95d77e06c88241c3bf809945fbd3a92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 6 Feb 2010 11:39:51 +0100 Subject: Routes should not swallow all NameErrors [#3862 status:resolved]. --- actionpack/lib/action_dispatch/routing/route_set.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index c49ac70562..dcf98b729b 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -44,7 +44,8 @@ module ActionDispatch controller = "#{params[:controller].camelize}Controller" ActiveSupport::Inflector.constantize(controller) end - rescue NameError + rescue NameError => e + raise unless e.message.include?(controller) nil end -- cgit v1.2.3 From 1d9d9d2d89a90a85f27a1909e3c435c070bc1b40 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Sat, 6 Feb 2010 21:36:46 +0700 Subject: Fix tiny version number from '3.0.0beta' to '3.0.0.beta1', so 'rake install' will be run correctly [#3879 status:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- actionpack/lib/action_pack/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_pack/version.rb b/actionpack/lib/action_pack/version.rb index 4dde21dd40..67f89e1627 100644 --- a/actionpack/lib/action_pack/version.rb +++ b/actionpack/lib/action_pack/version.rb @@ -2,7 +2,7 @@ module ActionPack #:nodoc: module VERSION #:nodoc: MAJOR = 3 MINOR = 0 - TINY = "0.beta" + TINY = "0.beta1" STRING = [MAJOR, MINOR, TINY].join('.') end -- cgit v1.2.3 From de69c798db5535f19bfd585da83117fe1dacd6d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 6 Feb 2010 20:55:25 +0100 Subject: Fix nested attributes with specified collection. --- actionpack/lib/action_view/helpers/form_helper.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 238f2eb07a..ce21af9923 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1172,7 +1172,9 @@ module ActionView def fields_for_with_nested_attributes(association_name, args, block) name = "#{object_name}[#{association_name}_attributes]" - association = args.first.to_model if args.first.respond_to?(:to_model) + options = args.extract_options! + association = args.shift + association = association.to_model if association.respond_to?(:to_model) if association.respond_to?(:new_record?) association = [association] if @object.send(association_name).is_a?(Array) @@ -1181,20 +1183,22 @@ module ActionView end if association.is_a?(Array) - explicit_child_index = args.last[:child_index] if args.last.is_a?(Hash) + explicit_child_index = options[:child_index] association.map do |child| - fields_for_nested_model("#{name}[#{explicit_child_index || nested_child_index(name)}]", child, args, block) + fields_for_nested_model("#{name}[#{explicit_child_index || nested_child_index(name)}]", child, options, block) end.join elsif association - fields_for_nested_model(name, association, args, block) + fields_for_nested_model(name, association, options, block) end end - def fields_for_nested_model(name, object, args, block) + def fields_for_nested_model(name, object, options, block) + object = object.to_model if object.respond_to?(:to_model) + if object.new_record? - @template.fields_for(name, object, *args, &block) + @template.fields_for(name, object, options, &block) else - @template.fields_for(name, object, *args) do |builder| + @template.fields_for(name, object, options) do |builder| block.call(builder) @template.concat builder.hidden_field(:id) unless builder.emitted_hidden_id? end -- cgit v1.2.3 From b235af702a086dd06fa9849ee47942e8ce82090d Mon Sep 17 00:00:00 2001 From: Gabriel Mansour Date: Sat, 30 Jan 2010 12:38:33 -0500 Subject: Fix pluralization for numbers formatted like '1.00' Signed-off-by: Jeremy Kemper --- actionpack/lib/action_view/helpers/text_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 412e0c82cb..b63617322f 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -187,7 +187,7 @@ module ActionView # pluralize(0, 'person') # # => 0 people def pluralize(count, singular, plural = nil) - "#{count || 0} " + ((count == 1 || count == '1') ? singular : (plural || singular.pluralize)) + "#{count || 0} " + ((count == 1 || count =~ /^1(\.0+)?$/) ? singular : (plural || singular.pluralize)) end # Wraps the +text+ into lines no longer than +line_width+ width. This method -- cgit v1.2.3 From ea8f9880c446e46952148d5ed770258674f88949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 9 Feb 2010 08:38:33 -0700 Subject: Remove outdated docs. --- .../lib/action_dispatch/middleware/show_exceptions.rb | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb index 3bcd004e12..43440e5f7c 100644 --- a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb +++ b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb @@ -5,20 +5,6 @@ require 'action_dispatch/http/request' module ActionDispatch # This middleware rescues any exception returned by the application and renders # nice exception pages if it's being rescued locally. - # - # Every time an exception is caught, a notification is published, becoming a good API - # to deal with exceptions. So, if you want send an e-mail through ActionMailer - # everytime this notification is published, you just need to do the following: - # - # ActiveSupport::Notifications.subscribe "action_dispatch.show_exception" do |name, start, end, instrumentation_id, payload| - # ExceptionNotifier.deliver_exception(start, payload) - # end - # - # The payload is a hash which has two pairs: - # - # * :env - Contains the rack env for the given request; - # * :exception - The exception raised; - # class ShowExceptions LOCALHOST = ['127.0.0.1', '::1'].freeze -- cgit v1.2.3 From fa2ff95d4b783751f42378447331385c469e4775 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 9 Feb 2010 17:23:48 -0800 Subject: Its not a deprecation if you actually just ignore the call --- actionpack/lib/action_controller/metal/compatibility.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/metal/compatibility.rb b/actionpack/lib/action_controller/metal/compatibility.rb index 1d4a719aa6..a1cfa32d4d 100644 --- a/actionpack/lib/action_controller/metal/compatibility.rb +++ b/actionpack/lib/action_controller/metal/compatibility.rb @@ -76,6 +76,7 @@ module ActionController def consider_all_requests_local=(value) ActiveSupport::Deprecation.warn "ActionController::Base.consider_all_requests_local= is no longer effective. " << "Please configure it on your application with config.consider_all_requests_local=" + Rails.application.config.consider_all_requests_local = value end def allow_concurrency @@ -87,6 +88,7 @@ module ActionController def allow_concurrency=(value) ActiveSupport::Deprecation.warn "ActionController::Base.allow_concurrency= is no longer effective. " << "Please configure it on your application with config.allow_concurrency=" + Rails.application.config.allow_concurrency = value end def rescue_action(env) -- cgit v1.2.3 From 325fa58ef585b4303a41270e231918f298ee30bd Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 12 Feb 2010 16:38:24 -0800 Subject: Safely concat the ending tag to simple_format or it will be escaped --- actionpack/lib/action_view/helpers/text_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index b63617322f..d84515d5b5 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -332,7 +332,7 @@ module ActionView text.gsub!(/\n\n+/, "

\n\n#{start_tag}") # 2+ newline -> paragraph text.gsub!(/([^\n]\n)(?=[^\n])/, '\1
') # 1 newline -> br text.insert 0, start_tag - text << "

" + text.safe_concat("

") end # Turns all URLs and e-mail addresses into clickable links. The :link option -- cgit v1.2.3 From d68f8ba5c303556ecb8625dd146184d68b704e83 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 12 Feb 2010 17:24:04 -0800 Subject: simple_format returns a safe buffer escaping unsafe input [Santiago Pastorino] --- actionpack/lib/action_view/helpers/text_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index d84515d5b5..b19a9754f4 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -327,7 +327,7 @@ module ActionView # # => "

Look ma! A class!

" def simple_format(text, html_options={}) start_tag = tag('p', html_options, true) - text = text.to_s.dup + text = h(text) text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n text.gsub!(/\n\n+/, "

\n\n#{start_tag}") # 2+ newline -> paragraph text.gsub!(/([^\n]\n)(?=[^\n])/, '\1
') # 1 newline -> br -- cgit v1.2.3 From 2f3eefcdca1d5dda42be1456349b8c6c79195f1e Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sat, 27 Feb 2010 09:29:51 +1100 Subject: Nitpick: the first value should be odd, second is even. --- actionpack/lib/action_view/helpers/text_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 644f34dbbe..e1ce65f90a 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -415,7 +415,7 @@ module ActionView # {:first => 'Emily', :middle => 'Shannon', :maiden => 'Pike', :last => 'Hicks'}, # {:first => 'June', :middle => 'Dae', :last => 'Jones'}] # <% @items.each do |item| %> - # "row_class") -%>"> + # "row_class") -%>"> # # <% item.values.each do |value| %> # <%# Create a named cycle "colors" %> -- cgit v1.2.3