From 19edc9116b2bafe301b9362b09d3f744fc777e09 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 4 May 2008 23:04:54 +0200 Subject: revised conventions for lists of options in selector_assertions.rb --- .../assertions/selector_assertions.rb | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/assertions/selector_assertions.rb b/actionpack/lib/action_controller/assertions/selector_assertions.rb index 272b8f6841..9ef093acfc 100644 --- a/actionpack/lib/action_controller/assertions/selector_assertions.rb +++ b/actionpack/lib/action_controller/assertions/selector_assertions.rb @@ -21,11 +21,11 @@ module ActionController # from the response HTML or elements selected by the enclosing assertion. # # In addition to HTML responses, you can make the following assertions: - # * #assert_select_rjs -- Assertions on HTML content of RJS update and + # * +assert_select_rjs+ - Assertions on HTML content of RJS update and # insertion operations. - # * #assert_select_encoded -- Assertions on HTML encoded inside XML, + # * +assert_select_encoded+ - Assertions on HTML encoded inside XML, # for example for dealing with feed item descriptions. - # * #assert_select_email -- Assertions on the HTML body of an e-mail. + # * +assert_select_email+ - Assertions on the HTML body of an e-mail. # # Also see HTML::Selector to learn how to use selectors. module SelectorAssertions @@ -136,27 +136,27 @@ module ActionController # === Equality Tests # # The equality test may be one of the following: - # * true -- Assertion is true if at least one element selected. - # * false -- Assertion is true if no element selected. - # * String/Regexp -- Assertion is true if the text value of at least + # * true - Assertion is true if at least one element selected. + # * false - Assertion is true if no element selected. + # * String/Regexp - Assertion is true if the text value of at least # one element matches the string or regular expression. - # * Integer -- Assertion is true if exactly that number of + # * Integer - Assertion is true if exactly that number of # elements are selected. - # * Range -- Assertion is true if the number of selected + # * Range - Assertion is true if the number of selected # elements fit the range. # If no equality test specified, the assertion is true if at least one # element selected. # # To perform more than one equality tests, use a hash with the following keys: - # * :text -- Narrow the selection to elements that have this text + # * :text - Narrow the selection to elements that have this text # value (string or regexp). - # * :html -- Narrow the selection to elements that have this HTML + # * :html - Narrow the selection to elements that have this HTML # content (string or regexp). - # * :count -- Assertion is true if the number of selected elements + # * :count - Assertion is true if the number of selected elements # is equal to this value. - # * :minimum -- Assertion is true if the number of selected + # * :minimum - Assertion is true if the number of selected # elements is at least this value. - # * :maximum -- Assertion is true if the number of selected + # * :maximum - Assertion is true if the number of selected # elements is at most this value. # # If the method is called with a block, once all equality tests are -- cgit v1.2.3 From 03e68ec80f393ee3b7ea0276b074268c90e722cf Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 4 May 2008 23:05:57 +0200 Subject: revised conventions for lists of options in action_controller/base.rb --- actionpack/lib/action_controller/base.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 6b5914c4dd..35c6e19ad8 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -535,20 +535,20 @@ module ActionController #:nodoc: # # url_for is used to: # - # All keys given to url_for are forwarded to the Route module, save for the following: - # * :anchor -- specifies the anchor name to be appended to the path. For example, + # All keys given to +url_for+ are forwarded to the Route module, save for the following: + # * :anchor - Specifies the anchor name to be appended to the path. For example, # url_for :controller => 'posts', :action => 'show', :id => 10, :anchor => 'comments' # will produce "/posts/show/10#comments". - # * :only_path -- if true, returns the relative URL (omitting the protocol, host name, and port) (false by default) - # * :trailing_slash -- if true, adds a trailing slash, as in "/archive/2005/". Note that this + # * :only_path - If true, returns the relative URL (omitting the protocol, host name, and port) (false by default). + # * :trailing_slash - If true, adds a trailing slash, as in "/archive/2005/". Note that this # is currently not recommended since it breaks caching. - # * :host -- overrides the default (current) host if provided. - # * :protocol -- overrides the default (current) protocol if provided. - # * :port -- optionally specify the port to connect to. - # * :user -- Inline HTTP authentication (only plucked out if :password is also present). - # * :password -- Inline HTTP authentication (only plucked out if :user is also present). - # * :skip_relative_url_root -- if true, the url is not constructed using the relative_url_root of the request so the path - # will include the web server relative installation directory. + # * :host - Overrides the default (current) host if provided. + # * :protocol - Overrides the default (current) protocol if provided. + # * :port - Optionally specify the port to connect to. + # * :user - Inline HTTP authentication (only plucked out if :password is also present). + # * :password - Inline HTTP authentication (only plucked out if :user is also present). + # * :skip_relative_url_root - If true, the url is not constructed using the +relative_url_root+ + # of the request so the path will include the web server relative installation directory. # # The URL is generated from the remaining keys in the hash. A URL contains two key parts: the and a query string. # Routes composes a query string as the key/value pairs not included in the . -- cgit v1.2.3 From 50c96f23df12d18e6f6e33673b80754c8bea8866 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 4 May 2008 23:12:58 +0200 Subject: revised some conventions in polymorphic_routes.rb --- actionpack/lib/action_controller/polymorphic_routes.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/polymorphic_routes.rb b/actionpack/lib/action_controller/polymorphic_routes.rb index aa0e05dbd7..e2b7716aa2 100644 --- a/actionpack/lib/action_controller/polymorphic_routes.rb +++ b/actionpack/lib/action_controller/polymorphic_routes.rb @@ -47,25 +47,27 @@ module ActionController # Constructs a call to a named RESTful route for the given record and returns the # resulting URL string. For example: # - # polymorphic_url(post) - # # calls post_url(post) #=> "http://example.com/posts/1" + # # calls post_url(post) + # polymorphic_url(post) # => "http://example.com/posts/1" # # ==== Options - # * :action -- specifies the action prefix for the named route: - # :new, :edit or :formatted. Default is no prefix. - # * :routing_type -- :path or :url (default :url). + # + # * :action - Specifies the action prefix for the named route: + # :new, :edit, or :formatted. Default is no prefix. + # * :routing_type - Allowed values are :path or :url. + # Default is :url. # # ==== Examples # # # an Article record - # polymorphic_url(record) #-> article_url(record) + # polymorphic_url(record) # same as article_url(record) # # # a Comment record - # polymorphic_url(record) #-> comment_url(record) + # polymorphic_url(record) # same as comment_url(record) # # # it recognizes new records and maps to the collection # record = Comment.new - # polymorphic_url(record) #-> comments_url() + # polymorphic_url(record) # same as comments_url() # def polymorphic_url(record_or_hash_or_array, options = {}) if record_or_hash_or_array.kind_of?(Array) -- cgit v1.2.3 From 17d22e933a9bd590703b2f7f79f6d9cc1183a392 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 4 May 2008 23:24:20 +0200 Subject: revised some conventions in form_tag_helper.rb --- actionpack/lib/action_view/helpers/form_tag_helper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index f37b428b80..922a0662fe 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -316,12 +316,12 @@ module ActionView # Creates a submit button with the text value as the caption. # # ==== Options - # * :confirm => 'question?' -- This will add a JavaScript confirm + # * :confirm => 'question?' - This will add a JavaScript confirm # prompt with the question specified. If the user accepts, the form is # processed normally, otherwise no action is taken. - # * :disabled - If set to true, the user will not be able to use this input. + # * :disabled - If true, the user will not be able to use this input. # * :disable_with - Value of this parameter will be used as the value for a disabled version - # of the submit button when the form is submitted. + # of the submit button when the form is submitted. # * Any other key creates standard HTML options for the tag. # # ==== Examples -- cgit v1.2.3 From 3e7bd63ec5bd60d39145b480339c17b8a5c45273 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 4 May 2008 23:29:35 +0200 Subject: revised some conventions in url_helper.rb --- actionpack/lib/action_view/helpers/url_helper.rb | 28 ++++++++++++------------ 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 6d27494213..375ebfcdc5 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -19,15 +19,15 @@ module ActionView # need an unescaped url, pass :escape => false in the +options+. # # ==== Options - # * :anchor -- specifies the anchor name to be appended to the path. - # * :only_path -- if true, returns the relative URL (omitting the protocol, host name, and port) (true by default unless :host is specified) - # * :trailing_slash -- if true, adds a trailing slash, as in "/archive/2005/". Note that this + # * :anchor - Specifies the anchor name to be appended to the path. + # * :only_path - If true, returns the relative URL (omitting the protocol, host name, and port) (true by default unless :host is specified). + # * :trailing_slash - If true, adds a trailing slash, as in "/archive/2005/". Note that this # is currently not recommended since it breaks caching. - # * :host -- overrides the default (current) host if provided - # * :protocol -- overrides the default (current) protocol if provided - # * :user -- Inline HTTP authentication (only plucked out if :password is also present) - # * :password -- Inline HTTP authentication (only plucked out if :user is also present) - # * :escape -- Determines whether the returned URL will be HTML escaped or not (true by default) + # * :host - Overrides the default (current) host if provided. + # * :protocol - Overrides the default (current) protocol if provided. + # * :user - Inline HTTP authentication (only plucked out if :password is also present). + # * :password - Inline HTTP authentication (only plucked out if :user is also present). + # * :escape - Determines whether the returned URL will be HTML escaped or not (true by default). # # ==== Relying on named routes # @@ -91,14 +91,14 @@ module ActionView # a name, the link itself will become the name. # # ==== Options - # * :confirm => 'question?' -- This will add a JavaScript confirm + # * :confirm => 'question?' - This will add a JavaScript confirm # prompt with the question specified. If the user accepts, the link is # processed normally, otherwise no action is taken. - # * :popup => true || array of window options -- This will force the + # * :popup => true || array of window options - This will force the # link to open in a popup window. By passing true, a default browser window # will be opened with the URL. You can also specify an array of options # that are passed-thru to JavaScripts window.open method. - # * :method => symbol of HTTP verb -- This modifier will dynamically + # * :method => symbol of HTTP verb - This modifier will dynamically # create an HTML form and immediately submit the form for processing using # the HTTP verb specified. Useful for having links perform a POST operation # in dangerous actions like deleting a record (which search bots can follow @@ -178,9 +178,9 @@ module ActionView # The +options+ hash accepts the same options at url_for. # # There are a few special +html_options+: - # * :method -- specifies the anchor name to be appended to the path. - # * :disabled -- specifies the anchor name to be appended to the path. - # * :confirm -- This will add a JavaScript confirm + # * :method - Specifies the anchor name to be appended to the path. + # * :disabled - Specifies the anchor name to be appended to the path. + # * :confirm - This will add a JavaScript confirm # prompt with the question specified. If the user accepts, the link is # processed normally, otherwise no action is taken. # -- cgit v1.2.3 From 238acc81be4e7a7385cb0dbb0eb90c0e79c84dbf Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 5 May 2008 22:41:11 +0200 Subject: revised convention for lists in request_forgery_protection.rb --- actionpack/lib/action_controller/request_forgery_protection.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/request_forgery_protection.rb b/actionpack/lib/action_controller/request_forgery_protection.rb index 7e6961d25f..5daf14eb30 100644 --- a/actionpack/lib/action_controller/request_forgery_protection.rb +++ b/actionpack/lib/action_controller/request_forgery_protection.rb @@ -69,10 +69,10 @@ module ActionController #:nodoc: # # Valid Options: # - # * :only/:except - passed to the before_filter call. Set which actions are verified. + # * :only/:except - Passed to the before_filter call. Set which actions are verified. # * :secret - Custom salt used to generate the form_authenticity_token. # Leave this off if you are using the cookie session store. - # * :digest - Message digest used for hashing. Defaults to 'SHA1' + # * :digest - Message digest used for hashing. Defaults to 'SHA1'. def protect_from_forgery(options = {}) self.request_forgery_protection_token ||= :authenticity_token before_filter :verify_authenticity_token, :only => options.delete(:only), :except => options.delete(:except) -- cgit v1.2.3 From 8d78ac598c87887eb9d0b4c77ca69eb1bb279472 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 5 May 2008 22:45:27 +0200 Subject: revised conventions in resources.rb --- actionpack/lib/action_controller/resources.rb | 34 +++++++++++++-------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/resources.rb b/actionpack/lib/action_controller/resources.rb index 0f0fa27d74..f686d78ee3 100644 --- a/actionpack/lib/action_controller/resources.rb +++ b/actionpack/lib/action_controller/resources.rb @@ -236,27 +236,27 @@ module ActionController # which takes into account whether @message is a new record or not and generates the # path and method accordingly. # - # The #resources method accepts the following options to customize the resulting routes: - # * :collection - add named routes for other actions that operate on the collection. + # The +resources+ method accepts the following options to customize the resulting routes: + # * :collection - Add named routes for other actions that operate on the collection. # Takes a hash of #{action} => #{method}, where method is :get/:post/:put/:delete - # or :any if the method does not matter. These routes map to a URL like /messages/rss, with a route of rss_messages_url. - # * :member - same as :collection, but for actions that operate on a specific member. - # * :new - same as :collection, but for actions that operate on the new resource action. - # * :controller - specify the controller name for the routes. - # * :singular - specify the singular name used in the member routes. - # * :requirements - set custom routing parameter requirements. - # * :conditions - specify custom routing recognition conditions. Resources sets the :method value for the method-specific routes. - # * :as - specify a different resource name to use in the URL path. For example: + # or :any if the method does not matter. These routes map to a URL like /messages/rss, with a route of +rss_messages_url+. + # * :member - Same as :collection, but for actions that operate on a specific member. + # * :new - Same as :collection, but for actions that operate on the new resource action. + # * :controller - Specify the controller name for the routes. + # * :singular - Specify the singular name used in the member routes. + # * :requirements - Set custom routing parameter requirements. + # * :conditions - Specify custom routing recognition conditions. Resources sets the :method value for the method-specific routes. + # * :as - Specify a different resource name to use in the URL path. For example: # # products_path == '/productos' # map.resources :products, :as => 'productos' do |product| # # product_reviews_path(product) == '/productos/1234/comentarios' # product.resources :product_reviews, :as => 'comentarios' # end # - # * :has_one - specify nested resources, this is a shorthand for mapping singleton resources beneath the current. - # * :has_many - same has :has_one, but for plural resources. + # * :has_one - Specify nested resources, this is a shorthand for mapping singleton resources beneath the current. + # * :has_many - Same has :has_one, but for plural resources. # - # You may directly specify the routing association with has_one and has_many like: + # You may directly specify the routing association with +has_one+ and +has_many+ like: # # map.resources :notes, :has_one => :author, :has_many => [:comments, :attachments] # @@ -268,14 +268,14 @@ module ActionController # notes.resources :attachments # end # - # * :path_names - specify different names for the 'new' and 'edit' actions. For example: + # * :path_names - Specify different names for the 'new' and 'edit' actions. For example: # # new_products_path == '/productos/nuevo' # map.resources :products, :as => 'productos', :path_names => { :new => 'nuevo', :edit => 'editar' } # # You can also set default action names from an environment, like this: # config.action_controller.resources_path_names = { :new => 'nuevo', :edit => 'editar' } # - # * :path_prefix - set a prefix to the routes with required route variables. + # * :path_prefix - Set a prefix to the routes with required route variables. # # Weblog comments usually belong to a post, so you might use resources like: # @@ -296,7 +296,7 @@ module ActionController # article_comments_url(:article_id => @article) # article_comment_url(:article_id => @article, :id => @comment) # - # * :name_prefix - define a prefix for all generated routes, usually ending in an underscore. + # * :name_prefix - Define a prefix for all generated routes, usually ending in an underscore. # Use this if you have named routes that may clash. # # map.resources :tags, :path_prefix => '/books/:book_id', :name_prefix => 'book_' @@ -343,7 +343,7 @@ module ActionController # # --> GET /categories/7/messages/1 # # has named route "category_message" # - # The #resources method sets HTTP method restrictions on the routes it generates. For example, making an + # The +resources+ method sets HTTP method restrictions on the routes it generates. For example, making an # HTTP POST on new_message_url will raise a RoutingError exception. The default route in # config/routes.rb overrides this and allows invalid HTTP methods for resource routes. def resources(*entities, &block) -- cgit v1.2.3 From c3218300334ba8f916f5208e8df4e426efb69dfb Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 5 May 2008 22:47:07 +0200 Subject: revised conventions in url_for docs --- actionpack/lib/action_controller/url_rewriter.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/url_rewriter.rb b/actionpack/lib/action_controller/url_rewriter.rb index b143806818..3a38f23396 100644 --- a/actionpack/lib/action_controller/url_rewriter.rb +++ b/actionpack/lib/action_controller/url_rewriter.rb @@ -29,16 +29,16 @@ module ActionController # Generate a url based on the options provided, default_url_options and the # routes defined in routes.rb. The following options are supported: # - # * :only_path If true, the relative url is returned. Defaults to +false+. - # * :protocol The protocol to connect to. Defaults to 'http'. - # * :host Specifies the host the link should be targetted at. + # * :only_path - If true, the relative url is returned. Defaults to +false+. + # * :protocol - The protocol to connect to. Defaults to 'http'. + # * :host - Specifies the host the link should be targetted at. # If :only_path is false, this option must be # provided either explicitly, or via +default_url_options+. - # * :port Optionally specify the port to connect to. - # * :anchor An anchor name to be appended to the path. - # * :skip_relative_url_root If true, the url is not constructed using the + # * :port - Optionally specify the port to connect to. + # * :anchor - An anchor name to be appended to the path. + # * :skip_relative_url_root - If true, the url is not constructed using the # +relative_url_root+ set in ActionController::AbstractRequest.relative_url_root. - # * :trailing_slash If true, adds a trailing slash, as in "/archive/2009/" + # * :trailing_slash - If true, adds a trailing slash, as in "/archive/2009/" # # Any other key (:controller, :action, etc.) given to # +url_for+ is forwarded to the Routes module. -- cgit v1.2.3 From 284a930a93fbee16e25d06392779dbf2f03e9e12 Mon Sep 17 00:00:00 2001 From: Jonathan Dance Date: Tue, 6 May 2008 14:58:26 -0400 Subject: improvements to the page caching docs --- actionpack/lib/action_controller/caching.rb | 3 ++- actionpack/lib/action_controller/caching/pages.rb | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/caching.rb b/actionpack/lib/action_controller/caching.rb index 08cbd13876..c4063dfb4b 100644 --- a/actionpack/lib/action_controller/caching.rb +++ b/actionpack/lib/action_controller/caching.rb @@ -20,7 +20,8 @@ module ActionController #:nodoc: # # == Caching stores # - # All the caching stores from ActiveSupport::Cache is available to be used as backends for Action Controller caching. + # All the caching stores from ActiveSupport::Cache is available to be used as backends for Action Controller caching. This setting only + # affects action and fragment caching as page caching is always written to disk. # # Configuration examples (MemoryStore is the default): # diff --git a/actionpack/lib/action_controller/caching/pages.rb b/actionpack/lib/action_controller/caching/pages.rb index 7aa6ce154b..8ceac55a91 100644 --- a/actionpack/lib/action_controller/caching/pages.rb +++ b/actionpack/lib/action_controller/caching/pages.rb @@ -4,10 +4,11 @@ require 'uri' module ActionController #:nodoc: module Caching # Page caching is an approach to caching where the entire action output of is stored as a HTML file that the web server - # can serve without going through the Action Pack. This can be as much as 100 times faster than going through the process of dynamically - # generating the content. Unfortunately, this incredible speed-up is only available to stateless pages where all visitors - # are treated the same. Content management systems -- including weblogs and wikis -- have many pages that are a great fit - # for this approach, but account-based systems where people log in and manipulate their own data are often less likely candidates. + # can serve without going through the Action Pack. This is the fastest way to cache your content as opposed to going dynamically + # through the process of generating the content. Unfortunately, this incredible speed-up is only available to stateless pages + # where all visitors are treated the same. Content management systems -- including weblogs and wikis -- have many pages that are + # a great fit for this approach, but account-based systems where people log in and manipulate their own data are often less + # likely candidates. # # Specifying which actions to cache is done through the caches class method: # @@ -15,7 +16,7 @@ module ActionController #:nodoc: # caches_page :show, :new # end # - # This will generate cache files such as weblog/show/5 and weblog/new, which match the URLs used to trigger the dynamic + # This will generate cache files such as weblog/show/5.html and weblog/new.html, which match the URLs used to trigger the dynamic # generation. This is how the web server is able pick up a cache file when it exists and otherwise let the request pass on to # the Action Pack to generate it. # @@ -36,12 +37,16 @@ module ActionController #:nodoc: # == Setting the cache directory # # The cache directory should be the document root for the web server and is set using Base.page_cache_directory = "/document/root". - # For Rails, this directory has already been set to Rails.public_path (which is usually set to RAILS_ROOT + "/public"). + # For Rails, this directory has already been set to Rails.public_path (which is usually set to RAILS_ROOT + "/public"). Changing + # this setting can be useful to avoid naming conflicts with files in public/, but doing so will likely require configuring your + # web server to look in the new location for cached files. # # == Setting the cache extension # - # By default, the cache extension is .html, which makes it easy for the cached files to be picked up by the web server. If you want - # something else, like .php or .shtml, just set Base.page_cache_extension. + # Most Rails requests do not have an extension, such as /weblog/new. In these cases, the page caching mechanism will add one in + # order to make it easy for the cached files to be picked up properly by the web server. By default, this cache extension is .html. + # If you want something else, like .php or .shtml, just set Base.page_cache_extension. In cases where a request already has an + # extension, such as .xml or .rss, page caching will not add an extension. This allows it to work well with RESTful apps. module Pages def self.included(base) #:nodoc: base.extend(ClassMethods) -- cgit v1.2.3 From 88e4de5ab71388bd7f58713dfd15bb594971ae79 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Wed, 7 May 2008 11:23:54 +0200 Subject: revised a few details in session docs --- actionpack/lib/action_controller/base.rb | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 664e80dce4..e1bf005f39 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -159,28 +159,34 @@ module ActionController #:nodoc: # # Hello #{session[:person]} # - # For removing objects from the session, you can either assign a single key to nil, like session[:person] = nil, or you can - # remove the entire session with reset_session. + # For removing objects from the session, you can either assign a single key to +nil+: # - # Sessions are stored in a browser cookie that's cryptographically signed, but unencrypted, by default. This prevents - # the user from tampering with the session but also allows him to see its contents. + # # removes :person from session + # session[:person] = nil # - # Do not put secret information in session! + # or you can remove the entire session with +reset_session+. + # + # Sessions are stored by default in a browser cookie that's cryptographically signed, but unencrypted. + # This prevents the user from tampering with the session but also allows him to see its contents. + # + # Do not put secret information in cookie-based sessions! # # Other options for session storage are: # - # ActiveRecordStore: sessions are stored in your database, which works better than PStore with multiple app servers and, - # unlike CookieStore, hides your session contents from the user. To use ActiveRecordStore, set + # * ActiveRecordStore - Sessions are stored in your database, which works better than PStore with multiple app servers and, + # unlike CookieStore, hides your session contents from the user. To use ActiveRecordStore, set # - # config.action_controller.session_store = :active_record_store + # config.action_controller.session_store = :active_record_store # - # in your environment.rb and run rake db:sessions:create. + # in your config/environment.rb and run rake db:sessions:create. # - # MemCacheStore: sessions are stored as entries in your memcached cache. Set the session store type in environment.rb: + # * MemCacheStore - Sessions are stored as entries in your memcached cache. + # Set the session store type in config/environment.rb: # - # config.action_controller.session_store = :mem_cache_store + # config.action_controller.session_store = :mem_cache_store # - # This assumes that memcached has been installed and configured properly. See the MemCacheStore docs for more information. + # This assumes that memcached has been installed and configured properly. + # See the MemCacheStore docs for more information. # # == Responses # -- cgit v1.2.3 From 4bf5f67be9625274faaa4c14a32170d50e987cbe Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Wed, 7 May 2008 15:42:39 +0200 Subject: applied patch in http://rails.lighthouseapp.com/projects/8994/tickets/133-patch-prototype-helper-doc-patch --- .../lib/action_view/helpers/prototype_helper.rb | 42 ++++++++++++++++++---- 1 file changed, 36 insertions(+), 6 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index 908728c0e6..1b12aa8058 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -631,6 +631,27 @@ module ActionView # render(:update) { |page| page.update_time } # end # + # Calls to JavaScriptGenerator not matching a helper method below + # generate a proxy to the JavaScript Class named by the method called. + # + # Examples: + # + # # Generates: + # # Foo.init(); + # update_page do |page| + # page.foo.init + # end + # + # # Generates: + # # Event.observe('one', 'click', function () { + # # $('two').show(); + # # }); + # update_page do |page| + # page.event.observe('one', 'click') do |p| + # p[:two].show + # end + # end + # # You can also use PrototypeHelper#update_page_tag instead of # PrototypeHelper#update_page to wrap the generated JavaScript in a # + # # # javascript_include_tag "xmlhr.js" # => - # + # # # javascript_include_tag "common.javascript", "/elsewhere/cools" # => - # - # + # + # # # javascript_include_tag "http://www.railsapplication.com/xmlhr" # => # @@ -213,25 +214,25 @@ module ActionView # # # javascript_include_tag :defaults # => - # - # + # + # # ... - # + # # # * = The application.js file is only referenced if it exists # # Though it's not really recommended practice, if you need to extend the default JavaScript set for any reason - # (e.g., you're going to be using a certain .js file in every action), then take a look at the register_javascript_include_default method. + # (e.g., you're going to be using a certain .js file in every action), then take a look at the register_javascript_include_default method. # # You can also include all javascripts in the javascripts directory using :all as the source: # # javascript_include_tag :all # => - # - # + # + # # ... - # - # - # + # + # + # # # Note that the default javascript files will be included first. So Prototype and Scriptaculous are available to # all subsequently included files. @@ -249,23 +250,23 @@ module ActionView # # ==== Examples # javascript_include_tag :all, :cache => true # when ActionController::Base.perform_caching is false => - # - # + # + # # ... - # - # - # + # + # + # # # javascript_include_tag :all, :cache => true # when ActionController::Base.perform_caching is true => - # + # # # javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when ActionController::Base.perform_caching is false => - # - # - # + # + # + # # # javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when ActionController::Base.perform_caching is true => - # + # # # The :recursive option is also available for caching: # @@ -296,9 +297,9 @@ module ActionView # ActionView::Helpers::AssetTagHelper.register_javascript_expansion :monkey => ["head", "body", "tail"] # # javascript_include_tag :monkey # => - # - # - # + # + # + # def self.register_javascript_expansion(expansions) @@javascript_expansions.merge!(expansions) end @@ -313,9 +314,9 @@ module ActionView # ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion :monkey => ["head", "body", "tail"] # # stylesheet_link_tag :monkey # => - # - # - # + # + # + # def self.register_stylesheet_expansion(expansions) @@stylesheet_expansions.merge!(expansions) end @@ -334,13 +335,14 @@ module ActionView # Computes the path to a stylesheet asset in the public stylesheets directory. # If the +source+ filename has no extension, .css will be appended. - # Full paths from the document root will be passed through. + # Full paths from the document root are passed through, URLs remain + # untouched. Local files get a timestamp appended as query string. # Used internally by +stylesheet_link_tag+ to build the stylesheet path. # # ==== Examples - # stylesheet_path "style" # => /stylesheets/style.css - # stylesheet_path "dir/style.css" # => /stylesheets/dir/style.css - # stylesheet_path "/dir/style.css" # => /dir/style.css + # stylesheet_path "style" # => /stylesheets/style.css?1239622973 + # stylesheet_path "dir/style.css" # => /stylesheets/dir/style.css?1245586314 + # stylesheet_path "/dir/style.css" # => /dir/style.css?1240376589 # stylesheet_path "http://www.railsapplication.com/css/style" # => http://www.railsapplication.com/css/style.css # stylesheet_path "http://www.railsapplication.com/css/style.js" # => http://www.railsapplication.com/css/style.css def stylesheet_path(source) @@ -354,30 +356,30 @@ module ActionView # # ==== Examples # stylesheet_link_tag "style" # => - # + # # # stylesheet_link_tag "style.css" # => - # + # # # stylesheet_link_tag "http://www.railsapplication.com/style.css" # => # # # stylesheet_link_tag "style", :media => "all" # => - # + # # # stylesheet_link_tag "style", :media => "print" # => - # + # # # stylesheet_link_tag "random.styles", "/css/stylish" # => - # - # + # + # # # You can also include all styles in the stylesheets directory using :all as the source: # # stylesheet_link_tag :all # => - # - # - # + # + # + # # # If you want Rails to search in all the subdirectories under stylesheets, you should explicitly set :recursive: # @@ -392,20 +394,20 @@ module ActionView # # ==== Examples # stylesheet_link_tag :all, :cache => true # when ActionController::Base.perform_caching is false => - # - # - # + # + # + # # # stylesheet_link_tag :all, :cache => true # when ActionController::Base.perform_caching is true => - # + # # # stylesheet_link_tag "shop", "cart", "checkout", :cache => "payment" # when ActionController::Base.perform_caching is false => - # - # - # + # + # + # # # stylesheet_link_tag "shop", "cart", "checkout", :cache => "payment" # when ActionController::Base.perform_caching is true => - # + # # # The :recursive option is also available for caching: # @@ -427,14 +429,15 @@ module ActionView end # Computes the path to an image asset in the public images directory. - # Full paths from the document root will be passed through. + # Full paths from the document root are passed through, URLs remain + # untouched. Local files get a timestamp appended as query string. # Used internally by +image_tag+ to build the image path. # # ==== Examples - # image_path("edit") # => /images/edit - # image_path("edit.png") # => /images/edit.png - # image_path("icons/edit.png") # => /images/icons/edit.png - # image_path("/icons/edit.png") # => /icons/edit.png + # image_path("edit") # => /images/edit?1245327490 + # image_path("edit.png") # => /images/edit.png?1239622973 + # image_path("icons/edit.png") # => /images/icons/edit.png?1239667843 + # image_path("/icons/edit.png") # => /icons/edit.png?1240376589 # image_path("http://www.railsapplication.com/img/edit.png") # => http://www.railsapplication.com/img/edit.png def image_path(source) compute_public_path(source, 'images') @@ -459,21 +462,21 @@ module ActionView # # ==== Examples # image_tag("icon") # => - # Icon + # Icon # image_tag("icon.png") # => # Icon - # image_tag("icon.png", :size => "16x10", :alt => "Edit Entry") # => + # image_tag("icon.png?1239667843", :size => "16x10", :alt => "Edit Entry") # => # Edit Entry # image_tag("/icons/icon.gif", :size => "16x16") # => - # Icon + # Icon # image_tag("/icons/icon.gif", :height => '32', :width => '32') # => - # Icon + # Icon # image_tag("/icons/icon.gif", :class => "menu_icon") # => - # Icon + # Icon # image_tag("mouse.png", :mouseover => "/images/mouse_over.png") # => - # Mouse + # Mouse # image_tag("mouse.png", :mouseover => image_path("mouse_over.png")) # => - # Mouse + # Mouse def image_tag(source, options = {}) options.symbolize_keys! -- cgit v1.2.3 From ba84025eb47c8a45846f410bed794414f68edbad Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 27 Apr 2009 19:03:20 +0200 Subject: fixes an example from the previous commit --- actionpack/lib/action_view/helpers/asset_tag_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 46b0fd2454..bfda866a55 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -465,8 +465,8 @@ module ActionView # Icon # image_tag("icon.png") # => # Icon - # image_tag("icon.png?1239667843", :size => "16x10", :alt => "Edit Entry") # => - # Edit Entry + # image_tag("icon.png", :size => "16x10", :alt => "Edit Entry") # => + # Edit Entry # image_tag("/icons/icon.gif", :size => "16x16") # => # Icon # image_tag("/icons/icon.gif", :height => '32', :width => '32') # => -- cgit v1.2.3 From 4df9680a6fe6608e8a82924f52e51a028a8575e5 Mon Sep 17 00:00:00 2001 From: Luke Amdor Date: Mon, 27 Apr 2009 11:30:08 -0500 Subject: Removed reference in documentation of form_authenticity_token to deprecated :secret option of protect_from_forgery --- actionpack/lib/action_controller/base/request_forgery_protection.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/base/request_forgery_protection.rb b/actionpack/lib/action_controller/base/request_forgery_protection.rb index 3067122ceb..df91dc1006 100644 --- a/actionpack/lib/action_controller/base/request_forgery_protection.rb +++ b/actionpack/lib/action_controller/base/request_forgery_protection.rb @@ -96,8 +96,7 @@ module ActionController #:nodoc: !request.content_type.nil? && request.content_type.verify_request? end - # Sets the token value for the current session. Pass a :secret option - # in +protect_from_forgery+ to add a custom salt to the hash. + # Sets the token value for the current session. def form_authenticity_token session[:_csrf_token] ||= ActiveSupport::SecureRandom.base64(32) end -- cgit v1.2.3 From 1b32f882091ed7744654f74238f3f3b1ba6701ae Mon Sep 17 00:00:00 2001 From: Simon Tokumine Date: Fri, 1 May 2009 19:55:02 +0100 Subject: bugfix for with_options routing documentation --- actionpack/lib/action_controller/routing.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb index c0eb61340b..82b36131f5 100644 --- a/actionpack/lib/action_controller/routing.rb +++ b/actionpack/lib/action_controller/routing.rb @@ -135,7 +135,7 @@ module ActionController # # In routes.rb # map.with_options :controller => 'blog' do |blog| # blog.show '', :action => 'list' - # blog.delete 'delete/:id', :action => 'delete', + # blog.delete 'delete/:id', :action => 'delete' # blog.edit 'edit/:id', :action => 'edit' # end # -- cgit v1.2.3 From a97f3bdfa960738cc12c26a502b00daed3900167 Mon Sep 17 00:00:00 2001 From: Evan Farrar Date: Thu, 7 May 2009 12:35:38 -0500 Subject: Some spelling changes. --- actionpack/lib/action_controller.rb | 2 +- actionpack/lib/action_controller/base/base.rb | 2 +- actionpack/lib/action_controller/base/http_authentication.rb | 2 +- .../lib/action_controller/routing/generation/url_rewriter.rb | 2 +- actionpack/lib/action_controller/routing/route_set.rb | 2 +- actionpack/lib/action_controller/testing/test_case.rb | 4 ++-- actionpack/lib/action_view/helpers/form_helper.rb | 8 ++++---- actionpack/lib/action_view/helpers/text_helper.rb | 4 ++-- actionpack/lib/action_view/helpers/url_helper.rb | 2 +- actionpack/lib/action_view/template/path.rb | 4 ++-- 10 files changed, 16 insertions(+), 16 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb index aee6b9dc9f..426891184a 100644 --- a/actionpack/lib/action_controller.rb +++ b/actionpack/lib/action_controller.rb @@ -36,7 +36,7 @@ require File.join(File.dirname(__FILE__), "action_pack") module ActionController # TODO: Review explicit to see if they will automatically be handled by - # the initilizer if they are really needed. + # the initializer if they are really needed. def self.load_all! [Base, Request, Response, UrlRewriter, UrlWriter] [ActionDispatch::Http::Headers] diff --git a/actionpack/lib/action_controller/base/base.rb b/actionpack/lib/action_controller/base/base.rb index 14c4339c94..4429b8f0b7 100644 --- a/actionpack/lib/action_controller/base/base.rb +++ b/actionpack/lib/action_controller/base/base.rb @@ -330,7 +330,7 @@ module ActionController #:nodoc: cattr_accessor :use_accept_header self.use_accept_header = true - # Controls whether request forgergy protection is turned on or not. Turned off by default only in test mode. + # Controls whether request forgery protection is turned on or not. Turned off by default only in test mode. class_inheritable_accessor :allow_forgery_protection self.allow_forgery_protection = true diff --git a/actionpack/lib/action_controller/base/http_authentication.rb b/actionpack/lib/action_controller/base/http_authentication.rb index b6b5267c66..9219847cd0 100644 --- a/actionpack/lib/action_controller/base/http_authentication.rb +++ b/actionpack/lib/action_controller/base/http_authentication.rb @@ -271,7 +271,7 @@ module ActionController # # The nonce is opaque to the client. Composed of Time, and hash of Time with secret # key from the Rails session secret generated upon creation of project. Ensures - # the time cannot be modifed by client. + # the time cannot be modified by client. def nonce(time = Time.now) t = time.to_i hashed = [t, secret_key] diff --git a/actionpack/lib/action_controller/routing/generation/url_rewriter.rb b/actionpack/lib/action_controller/routing/generation/url_rewriter.rb index 16720b915b..9717582b5e 100644 --- a/actionpack/lib/action_controller/routing/generation/url_rewriter.rb +++ b/actionpack/lib/action_controller/routing/generation/url_rewriter.rb @@ -93,7 +93,7 @@ module ActionController # # * :only_path - If true, the relative url is returned. Defaults to +false+. # * :protocol - The protocol to connect to. Defaults to 'http'. - # * :host - Specifies the host the link should be targetted at. + # * :host - Specifies the host the link should be targeted at. # If :only_path is false, this option must be # provided either explicitly, or via +default_url_options+. # * :port - Optionally specify the port to connect to. diff --git a/actionpack/lib/action_controller/routing/route_set.rb b/actionpack/lib/action_controller/routing/route_set.rb index 70cd1f642d..e2ecc77eb1 100644 --- a/actionpack/lib/action_controller/routing/route_set.rb +++ b/actionpack/lib/action_controller/routing/route_set.rb @@ -155,7 +155,7 @@ module ActionController def define_url_helper(route, name, kind, options) selector = url_helper_name(name, kind) - # The segment keys used for positional paramters + # The segment keys used for positional parameters hash_access_method = hash_access_name(name, kind) diff --git a/actionpack/lib/action_controller/testing/test_case.rb b/actionpack/lib/action_controller/testing/test_case.rb index b020b755a0..beea174766 100644 --- a/actionpack/lib/action_controller/testing/test_case.rb +++ b/actionpack/lib/action_controller/testing/test_case.rb @@ -56,7 +56,7 @@ module ActionController # # ActionController::TestCase will automatically infer the controller under test # from the test class name. If the controller cannot be inferred from the test - # class name, you can explicity set it with +tests+. + # class name, you can explicitly set it with +tests+. # # class SpecialEdgeCaseWidgetsControllerTest < ActionController::TestCase # tests WidgetController @@ -195,7 +195,7 @@ module ActionController @controller.send(:initialize_current_url) end end - + # Cause the action to be rescued according to the regular rules for rescue_action when the visitor is not local def rescue_action_in_public! @request.remote_addr = '208.77.188.166' # example.com diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index a59829b23f..d03879dd76 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -246,7 +246,7 @@ module ActionView # labelling_form. # # The custom FormBuilder class is automatically merged with the options - # of a nested fields_for call, unless it's explicitely set. + # of a nested fields_for call, unless it's explicitly set. # # In many cases you will want to wrap the above in another helper, so you # could do something like the following: @@ -620,8 +620,8 @@ module ActionView # Returns a checkbox tag tailored for accessing a specified attribute (identified by +method+) on an object # assigned to the template (identified by +object+). This object must be an instance object (@object) and not a local object. - # It's intended that +method+ returns an integer and if that integer is above zero, then the checkbox is checked. - # Additional options on the input tag can be passed as a hash with +options+. The +checked_value+ defaults to 1 + # It's intended that +method+ returns an integer and if that integer is above zero, then the checkbox is checked. + # Additional options on the input tag can be passed as a hash with +options+. The +checked_value+ defaults to 1 # while the default +unchecked_value+ is set to 0 which is convenient for boolean values. # # ==== Gotcha @@ -1043,4 +1043,4 @@ module ActionView cattr_accessor :default_form_builder self.default_form_builder = ::ActionView::Helpers::FormBuilder end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 573b99b96e..f16e311d6c 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -431,7 +431,7 @@ module ActionView end # Returns the current cycle string after a cycle has been started. Useful - # for complex table highlighing or any other design need which requires + # for complex table highlighting or any other design need which requires # the current cycle string in more than one place. # # ==== Example @@ -539,7 +539,7 @@ module ActionView left, right = $`, $' # detect already linked URLs and URLs in the middle of a tag if left =~ /<[^>]+$/ && right =~ /^[^>]*>/ - # do not change string; URL is alreay linked + # do not change string; URL is already linked href else # don't include trailing punctuation character as part of the URL diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 36e0a78e93..2309ff962d 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -116,7 +116,7 @@ module ActionView # * :popup => true || array of window options - This will force the # link to open in a popup window. By passing true, a default browser window # will be opened with the URL. You can also specify an array of options - # that are passed-thru to JavaScripts window.open method. + # that are passed through to JavaScripts window.open method. # * :method => symbol of HTTP verb - This modifier will dynamically # create an HTML form and immediately submit the form for processing using # the HTTP verb specified. Useful for having links perform a POST operation diff --git a/actionpack/lib/action_view/template/path.rb b/actionpack/lib/action_view/template/path.rb index 478bf96c9a..6f8d7a9c74 100644 --- a/actionpack/lib/action_view/template/path.rb +++ b/actionpack/lib/action_view/template/path.rb @@ -23,7 +23,7 @@ module ActionView private # This is what child classes implement. No defaults are needed - # because Path guarentees that the arguments are present and + # because Path guarantees that the arguments are present and # normalized. def find_templates(name, details, prefix, partial) raise NotImplementedError @@ -149,4 +149,4 @@ module ActionView end end -end \ No newline at end of file +end -- cgit v1.2.3 From 1fee2fb996229236fb236bcef423930fdf1dfe2d Mon Sep 17 00:00:00 2001 From: "Thomas R. Koll" Date: Sun, 24 May 2009 11:46:10 +0200 Subject: Fixed a typo Writing "form element" instead of "FORM element" --- actionpack/lib/action_view/helpers/url_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 2309ff962d..2ecab0ad2a 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -248,7 +248,7 @@ module ActionView # using the link_to method with the :method modifier as described in # the link_to documentation. # - # The generated FORM element has a class name of button-to + # The generated form element has a class name of button-to # to allow styling of the form itself and its children. You can control # the form submission and input element behavior using +html_options+. # This method accepts the :method and :confirm modifiers @@ -259,7 +259,7 @@ module ActionView # to change the HTTP verb used to submit the form. # # ==== Options - # The +options+ hash accepts the same options at url_for. + # The +options+ hash accepts the same options as url_for. # # There are a few special +html_options+: # * :method - Specifies the anchor name to be appended to the path. -- cgit v1.2.3 From bd918ce75f300d8b8fef23b04ffa4bd9add0f6dc Mon Sep 17 00:00:00 2001 From: Lloyd Pick Date: Sun, 24 May 2009 15:15:02 -0400 Subject: Updated examples to use latest config structure --- actionpack/lib/action_view/helpers/asset_tag_helper.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index bfda866a55..63b181509a 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -22,7 +22,7 @@ module ActionView # For example, you'd define assets.example.com to be your asset # host this way: # - # ActionController::Base.asset_host = "assets.example.com" + # config.action_controller.asset_host = "assets.example.com" # # Helpers take that into account: # @@ -55,7 +55,7 @@ module ActionView # Alternatively, you can exert more control over the asset host by setting # +asset_host+ to a proc like this: # - # ActionController::Base.asset_host = Proc.new { |source| + # config.action_controller.asset_host = Proc.new { |source| # "http://assets#{rand(2) + 1}.example.com" # } # image_tag("rails.png") @@ -71,7 +71,7 @@ module ActionView # absolute path of the asset with any extensions and timestamps in place, # for example "/images/rails.png?1230601161". # - # ActionController::Base.asset_host = Proc.new { |source| + # config.action_controller.asset_host = Proc.new { |source| # if source.starts_with?('/images') # "http://images.example.com" # else @@ -90,7 +90,7 @@ module ActionView # have SSL certificates for each of the asset hosts this technique allows you # to avoid warnings in the client about mixed media. # - # ActionController::Base.asset_host = Proc.new { |source, request| + # config.action_controller.asset_host = Proc.new { |source, request| # if request.ssl? # "#{request.protocol}#{request.host_with_port}" # else -- cgit v1.2.3 From 91e32af7729bea97fc971ac3ef5d3b2755fb0248 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 24 May 2009 23:17:47 +0200 Subject: a few details here and there in url_helper.rb docs --- actionpack/lib/action_view/helpers/url_helper.rb | 93 ++++++++++++------------ 1 file changed, 46 insertions(+), 47 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 2ecab0ad2a..3883b80e5a 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -11,11 +11,11 @@ module ActionView # Returns the URL for the set of +options+ provided. This takes the # same options as +url_for+ in Action Controller (see the - # documentation for ActionController::Base#url_for). Note that by default - # :only_path is true so you'll get the relative /controller/action - # instead of the fully qualified URL like http://example.com/controller/action. + # documentation for ActionController::Base#url_for). Note that by default + # :only_path is true so you'll get the relative "/controller/action" + # instead of the fully qualified URL like "http://example.com/controller/action". # - # When called from a view, url_for returns an HTML escaped url. If you + # When called from a view, +url_for+ returns an HTML escaped url. If you # need an unescaped url, pass :escape => false in the +options+. # # ==== Options @@ -33,8 +33,8 @@ module ActionView # # If you instead of a hash pass a record (like an Active Record or Active Resource) as the options parameter, # you'll trigger the named route for that record. The lookup will happen on the name of the class. So passing - # a Workshop object will attempt to use the workshop_path route. If you have a nested route, such as - # admin_workshop_path you'll have to call that explicitly (it's impossible for url_for to guess that route). + # a Workshop object will attempt to use the +workshop_path+ route. If you have a nested route, such as + # +admin_workshop_path+ you'll have to call that explicitly (it's impossible for +url_for+ to guess that route). # # ==== Examples # <%= url_for(:action => 'index') %> @@ -96,10 +96,10 @@ module ActionView # Creates a link tag of the given +name+ using a URL created by the set # of +options+. See the valid options in the documentation for - # url_for. It's also possible to pass a string instead + # +url_for+. It's also possible to pass a string instead # of an options hash to get a link tag that uses the value of the string as the # href for the link, or use :back to link to the referrer - a JavaScript back - # link will be used in place of a referrer if none exists. If nil is passed as + # link will be used in place of a referrer if none exists. If +nil+ is passed as # a name, the link itself will become the name. # # ==== Signatures @@ -116,27 +116,22 @@ module ActionView # * :popup => true || array of window options - This will force the # link to open in a popup window. By passing true, a default browser window # will be opened with the URL. You can also specify an array of options - # that are passed through to JavaScripts window.open method. + # that are passed to the window.open JavaScript call. # * :method => symbol of HTTP verb - This modifier will dynamically # create an HTML form and immediately submit the form for processing using # the HTTP verb specified. Useful for having links perform a POST operation # in dangerous actions like deleting a record (which search bots can follow # while spidering your site). Supported verbs are :post, :delete and :put. # Note that if the user has JavaScript disabled, the request will fall back - # to using GET. If you are relying on the POST behavior, you should check - # for it in your controller's action by using the request object's methods - # for post?, delete? or put?. + # to using GET. If :href => '#' is used and the user has JavaScript + # disabled clicking the link will have no effect. If you are relying on the + # POST behavior, you should check for it in your controller's action by using + # the request object's methods for post?, delete? or put?. # * The +html_options+ will accept a hash of html attributes for the link tag. # - # Note that if the user has JavaScript disabled, the request will fall back - # to using GET. If :href => '#' is used and the user has JavaScript disabled - # clicking the link will have no effect. If you are relying on the POST - # behavior, your should check for it in your controller's action by using the - # request object's methods for post?, delete? or put?. - # # You can mix and match the +html_options+ with the exception of - # :popup and :method which will raise an ActionView::ActionViewError - # exception. + # :popup and :method which will raise an + # ActionView::ActionViewError exception. # # ==== Examples # Because it relies on +url_for+, +link_to+ supports both older-style controller/action/id arguments @@ -169,9 +164,11 @@ module ActionView # You can use a block as well if your link target is hard to fit into the name parameter. ERb example: # # <% link_to(@profile) do %> - # <%= @profile.name %> -- Check it out!! + # <%= @profile.name %> -- Check it out! # <% end %> - # # => David -- Check it out!! + # # => + # David -- Check it out! + # # # Classes and ids for CSS are easy to produce: # @@ -214,7 +211,9 @@ module ActionView # # => Delete Image + # m.setAttribute('value', 'delete');var s = document.createElement('input'); s.setAttribute('type', 'hidden'); + # s.setAttribute('name', 'authenticity_token'); s.setAttribute('value', 'Q/ttlxPYZ6R77B+vZ1sBkhj21G2isO9dpE6UtOHBApg='); + # f.appendChild(s)f.appendChild(m);f.submit(); };return false;">Delete Image def link_to(*args, &block) if block_given? options = args.first || {} @@ -245,14 +244,14 @@ module ActionView # by the set of +options+. This is the safest method to ensure links that # cause changes to your data are not triggered by search bots or accelerators. # If the HTML button does not work with your layout, you can also consider - # using the link_to method with the :method modifier as described in - # the link_to documentation. + # using the +link_to+ method with the :method modifier as described in + # the +link_to+ documentation. # # The generated form element has a class name of button-to # to allow styling of the form itself and its children. You can control # the form submission and input element behavior using +html_options+. # This method accepts the :method and :confirm modifiers - # described in the link_to documentation. If no :method modifier + # described in the +link_to+ documentation. If no :method modifier # is given, it will default to performing a POST operation. You can also # disable the button by passing :disabled => true in +html_options+. # If you are using RESTful routes, you can pass the :method @@ -316,7 +315,7 @@ module ActionView # Creates a link tag of the given +name+ using a URL created by the set of # +options+ unless the current request URI is the same as the links, in # which case only the name is returned (or the given block is yielded, if - # one exists). You can give link_to_unless_current a block which will + # one exists). You can give +link_to_unless_current+ a block which will # specialize the default behavior (e.g., show a "Start Here" link rather # than the link's text). # @@ -342,7 +341,7 @@ module ActionView #
  • About Us
  • # # - # The implicit block given to link_to_unless_current is evaluated if the current + # The implicit block given to +link_to_unless_current+ is evaluated if the current # action is the action given. So, if we had a comments page and wanted to render a # "Go Back" link instead of a link to the comments page, we could do something like this... # @@ -359,7 +358,7 @@ module ActionView # +options+ unless +condition+ is true, in which case only the name is # returned. To specialize the default behavior (i.e., show a login link rather # than just the plaintext link text), you can pass a block that - # accepts the name or the full argument list for link_to_unless. + # accepts the name or the full argument list for +link_to_unless+. # # ==== Examples # <%= link_to_unless(@current_user.nil?, "Reply", { :action => "reply" }) %> @@ -390,8 +389,8 @@ module ActionView # Creates a link tag of the given +name+ using a URL created by the set of # +options+ if +condition+ is true, in which case only the name is # returned. To specialize the default behavior, you can pass a block that - # accepts the name or the full argument list for link_to_unless (see the examples - # in link_to_unless). + # accepts the name or the full argument list for +link_to_unless+ (see the examples + # in +link_to_unless+). # # ==== Examples # <%= link_to_if(@current_user.nil?, "Login", { :controller => "sessions", :action => "new" }) %> @@ -415,27 +414,27 @@ module ActionView # also used as the name of the link unless +name+ is specified. Additional # HTML attributes for the link can be passed in +html_options+. # - # mail_to has several methods for hindering email harvesters and customizing + # +mail_to+ has several methods for hindering email harvesters and customizing # the email itself by passing special keys to +html_options+. # # ==== Options - # * :encode - This key will accept the strings "javascript" or "hex". - # Passing "javascript" will dynamically create and encode the mailto: link then + # * :encode - This key will accept the strings "javascript" or "hex". + # Passing "javascript" will dynamically create and encode the mailto link then # eval it into the DOM of the page. This method will not show the link on # the page if the user has JavaScript disabled. Passing "hex" will hex - # encode the +email_address+ before outputting the mailto: link. - # * :replace_at - When the link +name+ isn't provided, the + # encode the +email_address+ before outputting the mailto link. + # * :replace_at - When the link +name+ isn't provided, the # +email_address+ is used for the link label. You can use this option to # obfuscate the +email_address+ by substituting the @ sign with the string # given as the value. - # * :replace_dot - When the link +name+ isn't provided, the + # * :replace_dot - When the link +name+ isn't provided, the # +email_address+ is used for the link label. You can use this option to # obfuscate the +email_address+ by substituting the . in the email with the # string given as the value. - # * :subject - Preset the subject line of the email. + # * :subject - Preset the subject line of the email. # * :body - Preset the body of the email. - # * :cc - Carbon Copy addition recipients on the email. - # * :bcc - Blind Carbon Copy additional recipients on the email. + # * :cc - Carbon Copy addition recipients on the email. + # * :bcc - Blind Carbon Copy additional recipients on the email. # # ==== Examples # mail_to "me@domain.com" @@ -606,23 +605,23 @@ module ActionView submit_function << "f.submit();" end - # Processes the _html_options_ hash, converting the boolean + # Processes the +html_options+ hash, converting the boolean # attributes from true/false form into the form required by # HTML/XHTML. (An attribute is considered to be boolean if - # its name is listed in the given _bool_attrs_ array.) + # its name is listed in the given +bool_attrs+ array.) # - # More specifically, for each boolean attribute in _html_options_ + # More specifically, for each boolean attribute in +html_options+ # given as: # - # "attr" => bool_value + # "attr" => bool_value # - # if the associated _bool_value_ evaluates to true, it is + # if the associated +bool_value+ evaluates to true, it is # replaced with the attribute's name; otherwise the attribute is - # removed from the _html_options_ hash. (See the XHTML 1.0 spec, + # removed from the +html_options+ hash. (See the XHTML 1.0 spec, # section 4.5 "Attribute Minimization" for more: # http://www.w3.org/TR/xhtml1/#h-4.5) # - # Returns the updated _html_options_ hash, which is also modified + # Returns the updated +html_options+ hash, which is also modified # in place. # # Example: -- cgit v1.2.3 From ceac7203925930d5d46b3466cc432c37582f0742 Mon Sep 17 00:00:00 2001 From: Mike Gunderloy Date: Fri, 5 Jun 2009 08:26:27 -0500 Subject: Correct typo on add_month_numbers option (From: Sam Pohlenz ) --- actionpack/lib/action_view/helpers/date_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 72fe9a3232..51b77a9521 100644 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -114,7 +114,7 @@ module ActionView # "2" instead of "February"). # * :use_short_month - Set to true if you want to use the abbreviated month name instead of the full # name (e.g. "Feb" instead of "February"). - # * :add_month_number - Set to true if you want to show both, the month's number and name (e.g. + # * :add_month_numbers - Set to true if you want to show both, the month's number and name (e.g. # "2 - February" instead of "February"). # * :use_month_names - Set to an array with 12 month names if you want to customize month names. # Note: You can also use Rails' new i18n functionality for this. -- cgit v1.2.3 From d82ad19d26428d74bb05a0df74c006778c9b3333 Mon Sep 17 00:00:00 2001 From: Mike Gunderloy Date: Fri, 5 Jun 2009 08:30:41 -0500 Subject: Some general cleanup to the rdoc for date_select --- actionpack/lib/action_view/helpers/date_helper.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 51b77a9521..332743d55b 100644 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -112,12 +112,12 @@ module ActionView # ==== Options # * :use_month_numbers - Set to true if you want to use month numbers rather than month names (e.g. # "2" instead of "February"). - # * :use_short_month - Set to true if you want to use the abbreviated month name instead of the full - # name (e.g. "Feb" instead of "February"). - # * :add_month_numbers - Set to true if you want to show both, the month's number and name (e.g. + # * :use_short_month - Set to true if you want to use abbreviated month names instead of full + # month names (e.g. "Feb" instead of "February"). + # * :add_month_numbers - Set to true if you want to use both month numbers and month names (e.g. # "2 - February" instead of "February"). # * :use_month_names - Set to an array with 12 month names if you want to customize month names. - # Note: You can also use Rails' new i18n functionality for this. + # Note: You can also use Rails' i18n functionality for this. # * :date_separator - Specifies a string to separate the date fields. Default is "" (i.e. nothing). # * :start_year - Set the start year for the year select. Default is Time.now.year - 5. # * :end_year - Set the end year for the year select. Default is Time.now.year + 5. @@ -128,7 +128,7 @@ module ActionView # as a hidden field instead of showing a select field. Also note that this implicitly sets :discard_day to true. # * :discard_year - Set to true if you don't want to show a year select. This includes the year # as a hidden field instead of showing a select field. - # * :order - Set to an array containing :day, :month and :year do + # * :order - Set to an array containing :day, :month and :year to # customize the order in which the select fields are shown. If you leave out any of the symbols, the respective # select will not be shown (like when you set :discard_xxx => true. Defaults to the order defined in # the respective locale (e.g. [:year, :month, :day] in the en locale that ships with Rails). -- cgit v1.2.3 From 0fc481d7c834ae905ebb2e52f47c3c3656ebd1c9 Mon Sep 17 00:00:00 2001 From: danielc192 Date: Thu, 16 Jul 2009 12:53:29 -0700 Subject: The redirect_to method in ActionController supports the :params option, however this is not mentioned in the documentation. This commit adds this. It includes an example and a brief description of the :params option. --- actionpack/lib/action_controller/base/base.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/base/base.rb b/actionpack/lib/action_controller/base/base.rb index e541d24e31..7bed86a77b 100644 --- a/actionpack/lib/action_controller/base/base.rb +++ b/actionpack/lib/action_controller/base/base.rb @@ -114,6 +114,8 @@ module ActionController # * String starting with protocol:// (like http://) - Is passed straight through as the target for redirection. # * String not containing a protocol - The current protocol and host is prepended to the string. # * :back - Back to the page that issued the request. Useful for forms that are triggered from multiple places. + # * :params - A hash containing the parameters to be passed as a GET request + # # Short-hand for redirect_to(request.env["HTTP_REFERER"]) # # Examples: @@ -123,6 +125,7 @@ module ActionController # redirect_to "/images/screenshot.jpg" # redirect_to articles_url # redirect_to :back + # redirect_to articles_url, :params => {"name" => "Ruby"} # # The redirection happens as a "302 Moved" header unless otherwise specified. # -- cgit v1.2.3 From 2637c5eee1cc67f28055b54ef9cc9a71f1e7c8f2 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Fri, 17 Jul 2009 00:37:41 +0200 Subject: redirect_to forwards options to url_for if it is a Hash (the example with articles_url does not work indeed because of that), understanding :params is a particular case of that This reverts commit 0fc481d7c834ae905ebb2e52f47c3c3656ebd1c9. --- actionpack/lib/action_controller/base/base.rb | 3 --- 1 file changed, 3 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/base/base.rb b/actionpack/lib/action_controller/base/base.rb index 7bed86a77b..e541d24e31 100644 --- a/actionpack/lib/action_controller/base/base.rb +++ b/actionpack/lib/action_controller/base/base.rb @@ -114,8 +114,6 @@ module ActionController # * String starting with protocol:// (like http://) - Is passed straight through as the target for redirection. # * String not containing a protocol - The current protocol and host is prepended to the string. # * :back - Back to the page that issued the request. Useful for forms that are triggered from multiple places. - # * :params - A hash containing the parameters to be passed as a GET request - # # Short-hand for redirect_to(request.env["HTTP_REFERER"]) # # Examples: @@ -125,7 +123,6 @@ module ActionController # redirect_to "/images/screenshot.jpg" # redirect_to articles_url # redirect_to :back - # redirect_to articles_url, :params => {"name" => "Ruby"} # # The redirection happens as a "302 Moved" header unless otherwise specified. # -- cgit v1.2.3 From b2ef631f3933d64027f1962aeacbed4f122bb0a0 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sat, 25 Jul 2009 15:35:47 +0100 Subject: Revert asset tag changes --- .../lib/action_view/helpers/asset_tag_helper.rb | 149 ++++++++++----------- 1 file changed, 73 insertions(+), 76 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 5025891d25..3fde79dfa4 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -23,7 +23,7 @@ module ActionView # For example, you'd define assets.example.com to be your asset # host this way: # - # config.action_controller.asset_host = "assets.example.com" + # ActionController::Base.asset_host = "assets.example.com" # # Helpers take that into account: # @@ -56,7 +56,7 @@ module ActionView # Alternatively, you can exert more control over the asset host by setting # +asset_host+ to a proc like this: # - # config.action_controller.asset_host = Proc.new { |source| + # ActionController::Base.asset_host = Proc.new { |source| # "http://assets#{rand(2) + 1}.example.com" # } # image_tag("rails.png") @@ -72,7 +72,7 @@ module ActionView # absolute path of the asset with any extensions and timestamps in place, # for example "/images/rails.png?1230601161". # - # config.action_controller.asset_host = Proc.new { |source| + # ActionController::Base.asset_host = Proc.new { |source| # if source.starts_with?('/images') # "http://images.example.com" # else @@ -91,7 +91,7 @@ module ActionView # have SSL certificates for each of the asset hosts this technique allows you # to avoid warnings in the client about mixed media. # - # config.action_controller.asset_host = Proc.new { |source, request| + # ActionController::Base.asset_host = Proc.new { |source, request| # if request.ssl? # "#{request.protocol}#{request.host_with_port}" # else @@ -170,16 +170,15 @@ module ActionView ) end - # Computes the path to a JavaScript asset in the public javascripts directory. - # If the +source+ filename has no extension, .js will be appended. - # Full paths from the document root are passed through, URLs remain - # untouched. Local files get a timestamp appended as query string. - # Used internally by javascript_include_tag to build the script path. + # Computes the path to a javascript asset in the public javascripts directory. + # If the +source+ filename has no extension, .js will be appended. + # Full paths from the document root will be passed through. + # Used internally by javascript_include_tag to build the script path. # # ==== Examples - # javascript_path "xmlhr" # => /javascripts/xmlhr.js?1240848408 - # javascript_path "dir/xmlhr.js" # => /javascripts/dir/xmlhr.js?1239899358 - # javascript_path "/dir/xmlhr" # => /dir/xmlhr.js?1240300432 + # javascript_path "xmlhr" # => /javascripts/xmlhr.js + # javascript_path "dir/xmlhr.js" # => /javascripts/dir/xmlhr.js + # javascript_path "/dir/xmlhr" # => /dir/xmlhr.js # javascript_path "http://www.railsapplication.com/js/xmlhr" # => http://www.railsapplication.com/js/xmlhr.js # javascript_path "http://www.railsapplication.com/js/xmlhr.js" # => http://www.railsapplication.com/js/xmlhr.js def javascript_path(source) @@ -199,14 +198,14 @@ module ActionView # # ==== Examples # javascript_include_tag "xmlhr" # => - # + # # # javascript_include_tag "xmlhr.js" # => - # + # # # javascript_include_tag "common.javascript", "/elsewhere/cools" # => - # - # + # + # # # javascript_include_tag "http://www.railsapplication.com/xmlhr" # => # @@ -215,25 +214,25 @@ module ActionView # # # javascript_include_tag :defaults # => - # - # + # + # # ... - # + # # # * = The application.js file is only referenced if it exists # # Though it's not really recommended practice, if you need to extend the default JavaScript set for any reason - # (e.g., you're going to be using a certain .js file in every action), then take a look at the register_javascript_include_default method. + # (e.g., you're going to be using a certain .js file in every action), then take a look at the register_javascript_include_default method. # # You can also include all javascripts in the javascripts directory using :all as the source: # # javascript_include_tag :all # => - # - # + # + # # ... - # - # - # + # + # + # # # Note that the default javascript files will be included first. So Prototype and Scriptaculous are available to # all subsequently included files. @@ -251,23 +250,23 @@ module ActionView # # ==== Examples # javascript_include_tag :all, :cache => true # when ActionController::Base.perform_caching is false => - # - # + # + # # ... - # - # - # + # + # + # # # javascript_include_tag :all, :cache => true # when ActionController::Base.perform_caching is true => - # + # # # javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when ActionController::Base.perform_caching is false => - # - # - # + # + # + # # # javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when ActionController::Base.perform_caching is true => - # + # # # The :recursive option is also available for caching: # @@ -301,9 +300,9 @@ module ActionView # ActionView::Helpers::AssetTagHelper.register_javascript_expansion :monkey => ["head", "body", "tail"] # # javascript_include_tag :monkey # => - # - # - # + # + # + # def self.register_javascript_expansion(expansions) @@javascript_expansions.merge!(expansions) end @@ -318,9 +317,9 @@ module ActionView # ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion :monkey => ["head", "body", "tail"] # # stylesheet_link_tag :monkey # => - # - # - # + # + # + # def self.register_stylesheet_expansion(expansions) @@stylesheet_expansions.merge!(expansions) end @@ -339,14 +338,13 @@ module ActionView # Computes the path to a stylesheet asset in the public stylesheets directory. # If the +source+ filename has no extension, .css will be appended. - # Full paths from the document root are passed through, URLs remain - # untouched. Local files get a timestamp appended as query string. + # Full paths from the document root will be passed through. # Used internally by +stylesheet_link_tag+ to build the stylesheet path. # # ==== Examples - # stylesheet_path "style" # => /stylesheets/style.css?1239622973 - # stylesheet_path "dir/style.css" # => /stylesheets/dir/style.css?1245586314 - # stylesheet_path "/dir/style.css" # => /dir/style.css?1240376589 + # stylesheet_path "style" # => /stylesheets/style.css + # stylesheet_path "dir/style.css" # => /stylesheets/dir/style.css + # stylesheet_path "/dir/style.css" # => /dir/style.css # stylesheet_path "http://www.railsapplication.com/css/style" # => http://www.railsapplication.com/css/style.css # stylesheet_path "http://www.railsapplication.com/css/style.js" # => http://www.railsapplication.com/css/style.css def stylesheet_path(source) @@ -360,30 +358,30 @@ module ActionView # # ==== Examples # stylesheet_link_tag "style" # => - # + # # # stylesheet_link_tag "style.css" # => - # + # # # stylesheet_link_tag "http://www.railsapplication.com/style.css" # => # # # stylesheet_link_tag "style", :media => "all" # => - # + # # # stylesheet_link_tag "style", :media => "print" # => - # + # # # stylesheet_link_tag "random.styles", "/css/stylish" # => - # - # + # + # # # You can also include all styles in the stylesheets directory using :all as the source: # # stylesheet_link_tag :all # => - # - # - # + # + # + # # # If you want Rails to search in all the subdirectories under stylesheets, you should explicitly set :recursive: # @@ -398,20 +396,20 @@ module ActionView # # ==== Examples # stylesheet_link_tag :all, :cache => true # when ActionController::Base.perform_caching is false => - # - # - # + # + # + # # # stylesheet_link_tag :all, :cache => true # when ActionController::Base.perform_caching is true => - # + # # # stylesheet_link_tag "shop", "cart", "checkout", :cache => "payment" # when ActionController::Base.perform_caching is false => - # - # - # + # + # + # # # stylesheet_link_tag "shop", "cart", "checkout", :cache => "payment" # when ActionController::Base.perform_caching is true => - # + # # # The :recursive option is also available for caching: # @@ -442,15 +440,14 @@ module ActionView end # Computes the path to an image asset in the public images directory. - # Full paths from the document root are passed through, URLs remain - # untouched. Local files get a timestamp appended as query string. + # Full paths from the document root will be passed through. # Used internally by +image_tag+ to build the image path. # # ==== Examples - # image_path("edit") # => /images/edit?1245327490 - # image_path("edit.png") # => /images/edit.png?1239622973 - # image_path("icons/edit.png") # => /images/icons/edit.png?1239667843 - # image_path("/icons/edit.png") # => /icons/edit.png?1240376589 + # image_path("edit") # => /images/edit + # image_path("edit.png") # => /images/edit.png + # image_path("icons/edit.png") # => /images/icons/edit.png + # image_path("/icons/edit.png") # => /icons/edit.png # image_path("http://www.railsapplication.com/img/edit.png") # => http://www.railsapplication.com/img/edit.png def image_path(source) compute_public_path(source, 'images') @@ -505,21 +502,21 @@ module ActionView # # ==== Examples # image_tag("icon") # => - # Icon + # Icon # image_tag("icon.png") # => # Icon # image_tag("icon.png", :size => "16x10", :alt => "Edit Entry") # => - # Edit Entry + # Edit Entry # image_tag("/icons/icon.gif", :size => "16x16") # => - # Icon + # Icon # image_tag("/icons/icon.gif", :height => '32', :width => '32') # => - # Icon + # Icon # image_tag("/icons/icon.gif", :class => "menu_icon") # => - # Icon + # Icon # image_tag("mouse.png", :mouseover => "/images/mouse_over.png") # => - # Mouse + # Mouse # image_tag("mouse.png", :mouseover => image_path("mouse_over.png")) # => - # Mouse + # Mouse def image_tag(source, options = {}) options.symbolize_keys! -- cgit v1.2.3 From c52be361484f5a0df7e413bc6640cf1d4bcb5ef5 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sat, 22 Aug 2009 09:06:46 +1000 Subject: Add missing end ERB tag. --- actionpack/lib/action_view/helpers/sanitize_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/sanitize_helper.rb b/actionpack/lib/action_view/helpers/sanitize_helper.rb index d89b955317..e93034d224 100644 --- a/actionpack/lib/action_view/helpers/sanitize_helper.rb +++ b/actionpack/lib/action_view/helpers/sanitize_helper.rb @@ -21,7 +21,7 @@ module ActionView # # Custom Use (only the mentioned tags and attributes are allowed, nothing else) # - # <%= sanitize @article.body, :tags => %w(table tr td), :attributes => %w(id class style) + # <%= sanitize @article.body, :tags => %w(table tr td), :attributes => %w(id class style) %> # # Add table tags to the default allowed tags # -- cgit v1.2.3 From 0a1c7b9df101b1f5921be0e1569c7fd007bd784a Mon Sep 17 00:00:00 2001 From: Jeffrey Hardy Date: Thu, 27 Aug 2009 00:32:57 -0400 Subject: Use a more idiomatic redirect_to example in the flash docs --- actionpack/lib/action_controller/metal/flash.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/metal/flash.rb b/actionpack/lib/action_controller/metal/flash.rb index 590f9be3ac..8753253dc6 100644 --- a/actionpack/lib/action_controller/metal/flash.rb +++ b/actionpack/lib/action_controller/metal/flash.rb @@ -8,7 +8,7 @@ module ActionController #:nodoc: # def create # # save post # flash[:notice] = "Successfully created post" - # redirect_to posts_path(@post) + # redirect_to @post # end # # def show -- cgit v1.2.3 From 7f8196f9085748b12b18e12d7b5e2cdb639153cb Mon Sep 17 00:00:00 2001 From: Ben Orenstein Date: Fri, 30 Oct 2009 12:57:49 -0400 Subject: Fixed an example that was missing a colon for a hash-key. --- actionpack/lib/action_dispatch/testing/assertions/routing.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index e6d6b5a3ef..ce221df2cb 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -105,7 +105,7 @@ module ActionDispatch # assert_routing '/home', :controller => 'home', :action => 'index' # # # Test a route generated with a specific controller, action, and parameter (id) - # assert_routing '/entries/show/23', :controller => 'entries', :action => 'show', id => 23 + # assert_routing '/entries/show/23', :controller => 'entries', :action => 'show', :id => 23 # # # Assert a basic route (controller + default action), with an error message if it fails # assert_routing '/store', { :controller => 'store', :action => 'index' }, {}, {}, 'Route for store index not generated properly' -- cgit v1.2.3 From 14ee31cdd09ef100cd2cb9eb9bd50c3a6d5e7f45 Mon Sep 17 00:00:00 2001 From: Cheah Chu Yeow Date: Fri, 20 Nov 2009 14:06:42 +0800 Subject: Indicate that the :method routing condition can also accept an array of HTTP methods. --- actionpack/lib/action_dispatch/routing.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing.rb b/actionpack/lib/action_dispatch/routing.rb index 68ed1e3340..5063ab8072 100644 --- a/actionpack/lib/action_dispatch/routing.rb +++ b/actionpack/lib/action_dispatch/routing.rb @@ -193,9 +193,10 @@ module ActionDispatch # # With conditions you can define restrictions on routes. Currently the only valid condition is :method. # - # * :method - Allows you to specify which method can access the route. Possible values are :post, - # :get, :put, :delete and :any. The default value is :any, - # :any means that any method can access the route. + # * :method - Allows you to specify which HTTP method(s) can access the route. Possible values are + # :post, :get, :put, :delete and :any. Use an array to specify more + # than one method, e.g. [ :get, :post ]. The default value is :any, :any means that any + # method can access the route. # # Example: # -- cgit v1.2.3 From 0a9f8dc2ec77ea7da4808d1b33bab598d2366f09 Mon Sep 17 00:00:00 2001 From: Mike Naberezny Date: Sat, 21 Nov 2009 15:49:42 -0800 Subject: Updated link to RedCloth. --- actionpack/lib/action_view/helpers/text_helper.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (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 1d92bcb763..e10217b0f4 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -226,8 +226,7 @@ module ActionView # Returns the text with all the Textile[http://www.textism.com/tools/textile] codes turned into HTML tags. # # You can learn more about Textile's syntax at its website[http://www.textism.com/tools/textile]. - # This method is only available if RedCloth[http://whytheluckystiff.net/ruby/redcloth/] - # is available. + # This method is only available if RedCloth[http://redcloth.org/] is available. # # ==== Examples # textilize("*This is Textile!* Rejoice!") @@ -263,8 +262,7 @@ module ActionView # but without the bounding

    tag that RedCloth adds. # # You can learn more about Textile's syntax at its website[http://www.textism.com/tools/textile]. - # This method is requires RedCloth[http://whytheluckystiff.net/ruby/redcloth/] - # to be available. + # This method is requires RedCloth[http://redcloth.org/] to be available. # # ==== Examples # textilize_without_paragraph("*This is Textile!* Rejoice!") -- cgit v1.2.3 From a2bf741385720c32861ddff5149138cd81a79382 Mon Sep 17 00:00:00 2001 From: Mike Naberezny Date: Sat, 21 Nov 2009 15:51:59 -0800 Subject: Fixed grammar. --- 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 e10217b0f4..a3bee3e8c2 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -262,7 +262,7 @@ module ActionView # but without the bounding

    tag that RedCloth adds. # # You can learn more about Textile's syntax at its website[http://www.textism.com/tools/textile]. - # This method is requires RedCloth[http://redcloth.org/] to be available. + # This method is only available if RedCloth[http://redcloth.org/] is available. # # ==== Examples # textilize_without_paragraph("*This is Textile!* Rejoice!") -- cgit v1.2.3 From a5cf2a95f4a15b43cb6481a2483890e4666f0c87 Mon Sep 17 00:00:00 2001 From: Jonathan Lim Date: Mon, 30 Nov 2009 12:20:35 +0000 Subject: assert_routing with a hash as first argument, needs to enclose arguments in brackets --- actionpack/lib/action_dispatch/testing/assertions/routing.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index ce221df2cb..dcf5d55e53 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -114,7 +114,7 @@ module ActionDispatch # assert_routing 'controller/action/9', {:id => "9", :item => "square"}, {:controller => "controller", :action => "action"}, {}, {:item => "square"} # # # Tests a route with a HTTP method - # assert_routing { :method => 'put', :path => '/product/321' }, { :controller => "product", :action => "update", :id => "321" } + # assert_routing({ :method => 'put', :path => '/product/321' }, { :controller => "product", :action => "update", :id => "321" }) def assert_routing(path, options, defaults={}, extras={}, message=nil) assert_recognizes(options, path, extras, message) -- cgit v1.2.3 From 0da0072b0176c9552206131667711c7ce15d0eb8 Mon Sep 17 00:00:00 2001 From: Jonathan Lim Date: Mon, 30 Nov 2009 12:24:18 +0000 Subject: assert_recognizes with a hash as first argument, needs to enclose arguments in brackets --- actionpack/lib/action_dispatch/testing/assertions/routing.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index dcf5d55e53..f0cca9a5f2 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -12,29 +12,29 @@ module ActionDispatch # and a :method containing the required HTTP verb. # # # assert that POSTing to /items will call the create action on ItemsController - # assert_recognizes {:controller => 'items', :action => 'create'}, {:path => 'items', :method => :post} + # assert_recognizes({:controller => 'items', :action => 'create'}, {:path => 'items', :method => :post}) # # You can also pass in +extras+ with a hash containing URL parameters that would normally be in the query string. This can be used # to assert that values in the query string string will end up in the params hash correctly. To test query strings you must use the # extras argument, appending the query string on the path directly will not work. For example: # # # assert that a path of '/items/list/1?view=print' returns the correct options - # assert_recognizes {:controller => 'items', :action => 'list', :id => '1', :view => 'print'}, 'items/list/1', { :view => "print" } + # assert_recognizes({:controller => 'items', :action => 'list', :id => '1', :view => 'print'}, 'items/list/1', { :view => "print" }) # # The +message+ parameter allows you to pass in an error message that is displayed upon failure. # # ==== Examples # # Check the default route (i.e., the index action) - # assert_recognizes {:controller => 'items', :action => 'index'}, 'items' + # assert_recognizes({:controller => 'items', :action => 'index'}, 'items') # # # Test a specific action - # assert_recognizes {:controller => 'items', :action => 'list'}, 'items/list' + # assert_recognizes({:controller => 'items', :action => 'list'}, 'items/list') # # # Test an action with a parameter - # assert_recognizes {:controller => 'items', :action => 'destroy', :id => '1'}, 'items/destroy/1' + # assert_recognizes({:controller => 'items', :action => 'destroy', :id => '1'}, 'items/destroy/1') # # # Test a custom route - # assert_recognizes {:controller => 'items', :action => 'show', :id => '1'}, 'view/item1' + # assert_recognizes({:controller => 'items', :action => 'show', :id => '1'}, 'view/item1') # # # Check a Simply RESTful generated route # assert_recognizes list_items_url, 'items/list' -- cgit v1.2.3 From b67dc00eae310f61e02f1cae27ec78eb8c1c599b Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Wed, 16 Dec 2009 18:28:04 +1000 Subject: Add options_from_collection_for_select to select_tag doco [hat-tip to anathematic] --- actionpack/lib/action_view/helpers/form_tag_helper.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index 7688e786b1..048bedc7ba 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -55,6 +55,9 @@ module ActionView # * Any other key creates standard HTML attributes for the tag. # # ==== Examples + # select_tag "people", options_from_collection_for_select(@people, "name", "id") + # # + # # select_tag "people", "" # # => # -- cgit v1.2.3 From d62661b46476181213a776819b19d4137b1441e8 Mon Sep 17 00:00:00 2001 From: Daniel Schierbeck Date: Mon, 21 Dec 2009 14:55:40 +0100 Subject: Fix some typos in the docs for ActionController::Responder --- actionpack/lib/action_controller/metal/responder.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/metal/responder.rb b/actionpack/lib/action_controller/metal/responder.rb index e8e88e7479..0c6f1cc96a 100644 --- a/actionpack/lib/action_controller/metal/responder.rb +++ b/actionpack/lib/action_controller/metal/responder.rb @@ -1,7 +1,7 @@ module ActionController #:nodoc: - # Responder is responsible to expose a resource for different mime requests, + # Responder is responsible for exposing a resource to different mime requests, # usually depending on the HTTP verb. The responder is triggered when - # respond_with is called. The simplest case to study is a GET request: + # respond_with is called. The simplest case to study is a GET request: # # class PeopleController < ApplicationController # respond_to :html, :xml, :json @@ -12,17 +12,17 @@ module ActionController #:nodoc: # end # end # - # When a request comes, for example with format :xml, three steps happen: + # When a request comes in, for example for an XML response, three steps happen: # - # 1) responder searches for a template at people/index.xml; + # 1) the responder searches for a template at people/index.xml; # - # 2) if the template is not available, it will invoke :to_xml in the given resource; + # 2) if the template is not available, it will invoke #to_xml on the given resource; # - # 3) if the responder does not respond_to :to_xml, call :to_format on it. + # 3) if the responder does not respond_to :to_xml, call #to_format on it. # # === Builtin HTTP verb semantics # - # Rails default responder holds semantics for each HTTP verb. Depending on the + # The default Rails responder holds semantics for each HTTP verb. Depending on the # content type, verb and the resource status, it will behave differently. # # Using Rails default responder, a POST request for creating an object could @@ -55,7 +55,7 @@ module ActionController #:nodoc: # # === Nested resources # - # You can given nested resource as you do in form_for and polymorphic_url. + # You can supply nested resources as you do in form_for and polymorphic_url. # Consider the project has many tasks example. The create action for # TasksController would be like: # @@ -67,7 +67,7 @@ module ActionController #:nodoc: # end # # Giving an array of resources, you ensure that the responder will redirect to - # project_task_url instead of task_url. + # project_task_url instead of task_url. # # Namespaced and singleton resources requires a symbol to be given, as in # polymorphic urls. If a project has one manager which has many tasks, it @@ -75,7 +75,7 @@ module ActionController #:nodoc: # # respond_with(@project, :manager, @task) # - # Check polymorphic_url documentation for more examples. + # Check polymorphic_url documentation for more examples. # class Responder attr_reader :controller, :request, :format, :resource, :resources, :options -- cgit v1.2.3 From 02a31b9d8a46fcec2e8ef2c378ca4ce6070dd037 Mon Sep 17 00:00:00 2001 From: Daniel Schierbeck Date: Mon, 21 Dec 2009 23:50:54 +0100 Subject: Fix some more typos in ActionController::Responder --- actionpack/lib/action_controller/metal/responder.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/metal/responder.rb b/actionpack/lib/action_controller/metal/responder.rb index 0c6f1cc96a..e0932ff932 100644 --- a/actionpack/lib/action_controller/metal/responder.rb +++ b/actionpack/lib/action_controller/metal/responder.rb @@ -69,7 +69,7 @@ module ActionController #:nodoc: # Giving an array of resources, you ensure that the responder will redirect to # project_task_url instead of task_url. # - # Namespaced and singleton resources requires a symbol to be given, as in + # Namespaced and singleton resources require a symbol to be given, as in # polymorphic urls. If a project has one manager which has many tasks, it # should be invoked as: # @@ -116,7 +116,7 @@ module ActionController #:nodoc: navigation_behavior(e) end - # All others formats follow the procedure below. First we try to render a + # All other formats follow the procedure below. First we try to render a # template, if the template is not available, we verify if the resource # responds to :to_format and display it. # @@ -173,11 +173,11 @@ module ActionController #:nodoc: @default_response.call end - # display is just a shortcut to render a resource with the current format. + # Display is just a shortcut to render a resource with the current format. # # display @user, :status => :ok # - # For xml request is equivalent to: + # For XML requests it's equivalent to: # # render :xml => @user, :status => :ok # @@ -194,14 +194,14 @@ module ActionController #:nodoc: controller.render given_options.merge!(options).merge!(format => resource) end - # Check if the resource has errors or not. + # Check whether the resource has errors. # def has_errors? resource.respond_to?(:errors) && !resource.errors.empty? end - # By default, render the :edit action for html requests with failure, unless - # the verb is post. + # By default, render the :edit action for HTML requests with failure, unless + # the verb is POST. # def default_action @action || (request.post? ? :new : :edit) -- cgit v1.2.3 From 48142a704a00b8296bc26ae571ae430bf55b90a0 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Sun, 24 Jan 2010 19:26:40 +1100 Subject: Fixing up that _delete is no longer used on the form helper for accepts_nested_attributes_for, it is now _destroy --- actionpack/lib/action_view/helpers/form_helper.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 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 20e9916d62..157deebe40 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -395,7 +395,7 @@ module ActionView # accepts_nested_attributes_for :address, :allow_destroy => true # end # - # Now, when you use a form element with the _delete parameter, + # Now, when you use a form element with the _destroy parameter, # with a value that evaluates to +true+, you will destroy the associated # model (eg. 1, '1', true, or 'true'): # @@ -403,7 +403,7 @@ module ActionView # ... # <% person_form.fields_for :address do |address_fields| %> # ... - # Delete: <%= address_fields.check_box :_delete %> + # Delete: <%= address_fields.check_box :_destroy %> # <% end %> # <% end %> # @@ -476,14 +476,14 @@ module ActionView # end # # This will allow you to specify which models to destroy in the - # attributes hash by adding a form element for the _delete + # attributes hash by adding a form element for the _destroy # parameter with a value that evaluates to +true+ # (eg. 1, '1', true, or 'true'): # # <% form_for @person, :url => { :action => "update" } do |person_form| %> # ... # <% person_form.fields_for :projects do |project_fields| %> - # Delete: <%= project_fields.check_box :_delete %> + # Delete: <%= project_fields.check_box :_destroy %> # <% end %> # <% end %> def fields_for(record_or_name_or_array, *args, &block) -- cgit v1.2.3 From dfa19408651ecc82e2aeba95d93db871ba8a6e41 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 28 Jan 2010 11:18:32 +0100 Subject: removes unnecessary curlies in collection_select rdoc --- actionpack/lib/action_view/helpers/form_options_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index 02ad637509..d3e614b98f 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -149,7 +149,7 @@ module ActionView # end # # Sample usage (selecting the associated Author for an instance of Post, @post): - # collection_select(:post, :author_id, Author.all, :id, :name_with_initial, {:prompt => true}) + # collection_select(:post, :author_id, Author.all, :id, :name_with_initial, :prompt => true) # # If @post.author_id is already 1, this would return: # ...options... # - # <% content_tag :div, :class => "strong" do -%> + # <%= content_tag :div, :class => "strong" do -%> # Hello world! # <% end -%> # # =>

    Hello world!
    -- cgit v1.2.3 From e8d2f48cff858728280eef575e95c3b82ecd69d9 Mon Sep 17 00:00:00 2001 From: Jeroen van Dijk Date: Fri, 12 Mar 2010 13:21:52 +0100 Subject: Updated documentation for block helpers in record_tag_helper.rb --- actionpack/lib/action_view/helpers/record_tag_helper.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/record_tag_helper.rb b/actionpack/lib/action_view/helpers/record_tag_helper.rb index 31411dc08a..a9cf15f418 100644 --- a/actionpack/lib/action_view/helpers/record_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/record_tag_helper.rb @@ -4,7 +4,7 @@ module ActionView # Produces a wrapper DIV element with id and class parameters that # relate to the specified Active Record object. Usage example: # - # <% div_for(@person, :class => "foo") do %> + # <%= div_for(@person, :class => "foo") do %> # <%=h @person.name %> # <% end %> # @@ -19,7 +19,7 @@ module ActionView # content_tag_for creates an HTML element with id and class parameters # that relate to the specified Active Record object. For example: # - # <% content_tag_for(:tr, @person) do %> + # <%= content_tag_for(:tr, @person) do %> # <%=h @person.first_name %> # <%=h @person.last_name %> # <% end %> @@ -31,7 +31,7 @@ module ActionView # # If you require the HTML id attribute to have a prefix, you can specify it: # - # <% content_tag_for(:tr, @person, :foo) do %> ... + # <%= content_tag_for(:tr, @person, :foo) do %> ... # # produces: # @@ -41,7 +41,7 @@ module ActionView # additional HTML attributes. If you specify a :class value, it will be combined # with the default class name for your object. For example: # - # <% content_tag_for(:li, @person, :class => "bar") %>... + # <%= content_tag_for(:li, @person, :class => "bar") %>... # # produces: # -- cgit v1.2.3 From 363616572dcc2a9bb10b226b0a730667b29b4c1d Mon Sep 17 00:00:00 2001 From: Jeroen van Dijk Date: Fri, 12 Mar 2010 13:23:24 +0100 Subject: Updated documentation for block helpers in prototype_helper.rb --- actionpack/lib/action_view/helpers/prototype_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index 7eb6bceca0..51510449bd 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -35,7 +35,7 @@ module ActionView # # ...through a form... # - # <% form_remote_tag :url => '/shipping' do -%> + # <%= form_remote_tag :url => '/shipping' do -%> #
    <%= submit_tag 'Recalculate Shipping' %>
    # <% end -%> # -- cgit v1.2.3 From a098720719c0c99dea119612a31d9ba31bfdcbed Mon Sep 17 00:00:00 2001 From: Jeroen van Dijk Date: Fri, 12 Mar 2010 13:24:17 +0100 Subject: Updated documentation for block helpers in javascript_helper.rb --- actionpack/lib/action_view/helpers/javascript_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index 8fdaa8cf8d..0a901b2d2b 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -71,7 +71,7 @@ module ActionView # # Instead of passing the content as an argument, you can also use a block # in which case, you pass your +html_options+ as the first parameter. - # <% javascript_tag :defer => 'defer' do -%> + # <%= javascript_tag :defer => 'defer' do -%> # alert('All is good') # <% end -%> def javascript_tag(content_or_options_with_block = nil, html_options = {}, &block) -- cgit v1.2.3 From 67de0af60485b4da45d015e9a1dfad5439d5fca2 Mon Sep 17 00:00:00 2001 From: Jeroen van Dijk Date: Fri, 12 Mar 2010 13:25:56 +0100 Subject: Updated documentation for block helpers in form_tag_helper.rb --- actionpack/lib/action_view/helpers/form_tag_helper.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index 6ed6c3101b..9d76870646 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -32,12 +32,12 @@ module ActionView # form_tag('/upload', :multipart => true) # # =>
    # - # <% form_tag('/posts')do -%> + # <%= form_tag('/posts')do -%> #
    <%= submit_tag 'Save' %>
    # <% end -%> # # =>
    # - # <% form_tag('/posts', :remote => true) %> + # <%= form_tag('/posts', :remote => true) %> # # =>
    # def form_tag(url_for_options = {}, options = {}, *parameters_for_url, &block) @@ -425,17 +425,17 @@ module ActionView # options accept the same values as tag. # # ==== Examples - # <% field_set_tag do %> + # <%= field_set_tag do %> #

    <%= text_field_tag 'name' %>

    # <% end %> # # =>

    # - # <% field_set_tag 'Your details' do %> + # <%= field_set_tag 'Your details' do %> #

    <%= text_field_tag 'name' %>

    # <% end %> # # =>
    Your details

    # - # <% field_set_tag nil, :class => 'format' do %> + # <%= field_set_tag nil, :class => 'format' do %> #

    <%= text_field_tag 'name' %>

    # <% end %> # # =>

    -- cgit v1.2.3 From ef6462c73003b28c8e060a06120abb9cd67b6d52 Mon Sep 17 00:00:00 2001 From: Jeroen van Dijk Date: Fri, 12 Mar 2010 13:39:30 +0100 Subject: Updated documentation for block helpers in render/partials.rb --- actionpack/lib/action_view/render/partials.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/render/partials.rb b/actionpack/lib/action_view/render/partials.rb index 8b6dce0c1c..62d31662db 100644 --- a/actionpack/lib/action_view/render/partials.rb +++ b/actionpack/lib/action_view/render/partials.rb @@ -123,7 +123,7 @@ module ActionView # You can also apply a layout to a block within any template: # # <%# app/views/users/_chief.html.erb &> - # <% render(:layout => "administrator", :locals => { :user => chief }) do %> + # <%= render(:layout => "administrator", :locals => { :user => chief }) do %> # Title: <%= chief.title %> # <% end %> # @@ -146,7 +146,7 @@ module ActionView # # # <%# app/views/users/index.html.erb &> - # <% render :layout => @users do |user| %> + # <%= render :layout => @users do |user| %> # Title: <%= user.title %> # <% end %> # @@ -162,7 +162,7 @@ module ActionView # # # <%# app/views/users/index.html.erb &> - # <% render :layout => @users do |user, section| %> + # <%= render :layout => @users do |user, section| %> # <%- case section when :header -%> # Title: <%= user.title %> # <%- when :footer -%> -- cgit v1.2.3 From 20eb1ca77ef591e64e33d6c21dc997d89ea62e3d Mon Sep 17 00:00:00 2001 From: Jeroen van Dijk Date: Fri, 12 Mar 2010 13:39:47 +0100 Subject: Updated documentation for block helpers in render/layouts.rb --- actionpack/lib/action_view/render/layouts.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/render/layouts.rb b/actionpack/lib/action_view/render/layouts.rb index 8688de3d18..e9252dba9e 100644 --- a/actionpack/lib/action_view/render/layouts.rb +++ b/actionpack/lib/action_view/render/layouts.rb @@ -13,7 +13,7 @@ module ActionView # ==== Example # # # The template - # <% render :layout => "my_layout" do %>Content<% end %> + # <%= render :layout => "my_layout" do %>Content<% end %> # # # The layout # <% yield %> @@ -27,7 +27,7 @@ module ActionView # ==== Example # # # The template - # <% render :layout => "my_layout" do |customer| %>Hello <%= customer.name %><% end %> + # <%= render :layout => "my_layout" do |customer| %>Hello <%= customer.name %><% end %> # # # The layout # <% yield Struct.new(:name).new("David") %> -- cgit v1.2.3 From f2c0a353aef41a6df2de8e1fe3eaa3d8bbd8a6dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 12 Mar 2010 20:39:53 +0100 Subject: Finish cleaning up rendering stack from views and move assigns evaluation to controller (so plugins and/or controllers can overwrite just one method). --- actionpack/lib/abstract_controller.rb | 1 + actionpack/lib/abstract_controller/assigns.rb | 21 ++++++++++++ actionpack/lib/abstract_controller/layouts.rb | 6 ++++ actionpack/lib/abstract_controller/rendering.rb | 16 +++++----- .../lib/action_controller/metal/mime_responds.rb | 1 + .../lib/action_controller/metal/renderers.rb | 3 +- .../lib/action_controller/metal/rendering.rb | 21 ++++++------ actionpack/lib/action_view/base.rb | 9 ------ .../lib/action_view/helpers/prototype_helper.rb | 1 - actionpack/lib/action_view/render/layouts.rb | 5 +-- actionpack/lib/action_view/render/rendering.rb | 37 +++++----------------- .../lib/action_view/template/handlers/rjs.rb | 3 +- actionpack/lib/action_view/template/text.rb | 14 ++++---- 13 files changed, 66 insertions(+), 72 deletions(-) create mode 100644 actionpack/lib/abstract_controller/assigns.rb (limited to 'actionpack/lib') diff --git a/actionpack/lib/abstract_controller.rb b/actionpack/lib/abstract_controller.rb index 2da4dc052c..de95f935c2 100644 --- a/actionpack/lib/abstract_controller.rb +++ b/actionpack/lib/abstract_controller.rb @@ -12,6 +12,7 @@ require 'active_support/i18n' module AbstractController extend ActiveSupport::Autoload + autoload :Assigns autoload :Base autoload :Callbacks autoload :Collector diff --git a/actionpack/lib/abstract_controller/assigns.rb b/actionpack/lib/abstract_controller/assigns.rb new file mode 100644 index 0000000000..21459c6d51 --- /dev/null +++ b/actionpack/lib/abstract_controller/assigns.rb @@ -0,0 +1,21 @@ +module AbstractController + module Assigns + # This method should return a hash with assigns. + # You can overwrite this configuration per controller. + # :api: public + def view_assigns + hash = {} + variables = instance_variable_names + variables -= protected_instance_variables if respond_to?(:protected_instance_variables) + variables.each { |name| hash[name] = instance_variable_get(name) } + hash + end + + # This method assigns the hash specified in _assigns_hash to the given object. + # :api: private + # TODO Ideally, this should be done on AV::Base.new initialization. + def _evaluate_assigns(object) + view_assigns.each { |k,v| object.instance_variable_set(k, v) } + end + end +end \ No newline at end of file diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb index 2f9616124a..95a6101109 100644 --- a/actionpack/lib/abstract_controller/layouts.rb +++ b/actionpack/lib/abstract_controller/layouts.rb @@ -284,6 +284,12 @@ module AbstractController layout = options.key?(:layout) ? options.delete(:layout) : :default value = _layout_for_option(layout) options[:layout] = (value =~ /\blayouts/ ? value : "layouts/#{value}") if value + + # TODO Layout for partials should be handled here, because inside the + # partial renderer it looks for the layout as a partial. + if options.key?(:partial) && options[:layout] + options[:layout] = view_context.find_layout(options[:layout]) + end end end diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 42f4939108..16664098e5 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -31,6 +31,8 @@ module AbstractController module Rendering extend ActiveSupport::Concern + + include AbstractController::Assigns include AbstractController::ViewPaths # Overwrite process to setup I18n proxy. @@ -54,8 +56,8 @@ module AbstractController @_view_context ||= ActionView::Base.for_controller(self) end - # Mostly abstracts the fact that calling render twice is a DoubleRenderError. - # Delegates render_to_body and sticks the result in self.response_body. + # Normalize arguments, options and then delegates render_to_body and + # sticks the result in self.response_body. def render(*args, &block) options = _normalize_args(*args, &block) _normalize_options(options) @@ -78,8 +80,10 @@ module AbstractController end # Find and renders a template based on the options given. - def _render_template(options) - view_context.render_template(options) { |template| _with_template_hook(template) } + # :api: private + def _render_template(options) #:nodoc: + _evaluate_assigns(view_context) + view_context.render(options) end # The prefix used in render "foo" shortcuts. @@ -134,9 +138,5 @@ module AbstractController def _process_options(options) end - - def _with_template_hook(template) - self.formats = template.formats - end end end diff --git a/actionpack/lib/action_controller/metal/mime_responds.rb b/actionpack/lib/action_controller/metal/mime_responds.rb index e70a20b2be..2ac199265d 100644 --- a/actionpack/lib/action_controller/metal/mime_responds.rb +++ b/actionpack/lib/action_controller/metal/mime_responds.rb @@ -261,6 +261,7 @@ module ActionController #:nodoc: block.call(collector) if block_given? if format = request.negotiate_mime(collector.order) + self.content_type ||= format.to_s self.formats = [format.to_sym] collector.response_for(format) else diff --git a/actionpack/lib/action_controller/metal/renderers.rb b/actionpack/lib/action_controller/metal/renderers.rb index 49d3d6b466..08325b468c 100644 --- a/actionpack/lib/action_controller/metal/renderers.rb +++ b/actionpack/lib/action_controller/metal/renderers.rb @@ -87,8 +87,9 @@ module ActionController end add :update do |proc, options| + _evaluate_assigns(view_context) generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(view_context, &proc) - self.content_type = Mime::JS + self.content_type = Mime::JS self.response_body = generator.to_s end end diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb index f892bd9b91..2167fe9a32 100644 --- a/actionpack/lib/action_controller/metal/rendering.rb +++ b/actionpack/lib/action_controller/metal/rendering.rb @@ -5,26 +5,31 @@ module ActionController include ActionController::RackDelegation include AbstractController::Rendering - def process(*) + # Before processing, set the request formats in current controller formats. + def process(*) #:nodoc: self.formats = request.formats.map { |x| x.to_sym } super end - def render(*args) + # Check for double render errors and set the content_type after rendering. + def render(*args) #:nodoc: raise ::AbstractController::DoubleRenderError if response_body super + self.content_type ||= Mime[formats.first].to_s response_body end private - def _normalize_args(action=nil, options={}, &blk) + # Normalize arguments by catching blocks and setting them on :update. + def _normalize_args(action=nil, options={}, &blk) #:nodoc: options = super options[:update] = blk if block_given? options end - def _normalize_options(options) + # Normalize both text and status options. + def _normalize_options(options) #:nodoc: if options.key?(:text) && options[:text].respond_to?(:to_text) options[:text] = options[:text].to_text end @@ -36,7 +41,8 @@ module ActionController super end - def _process_options(options) + # Process controller specific options, as status, content-type and location. + def _process_options(options) #:nodoc: status, content_type, location = options.values_at(:status, :content_type, :location) self.status = status if status @@ -46,10 +52,5 @@ module ActionController super end - def _with_template_hook(template) - super - self.content_type ||= template.mime_type.to_s - end - end end diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index f1b1c22075..feaf45c333 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -264,14 +264,5 @@ module ActionView #:nodoc: response.body_parts << part nil end - - # Evaluates the local assigns and controller ivars, pushes them to the view. - def _evaluate_assigns_and_ivars #:nodoc: - if controller - variables = controller.instance_variable_names - variables -= controller.protected_instance_variables if controller.respond_to?(:protected_instance_variables) - variables.each { |name| instance_variable_set(name, controller.instance_variable_get(name)) } - end - end end end diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index be49b5cc28..e58fdf81fb 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -180,7 +180,6 @@ module ActionView # #include_helpers_from_context has nothing to overwrite. class JavaScriptGenerator #:nodoc: def initialize(context, &block) #:nodoc: - context._evaluate_assigns_and_ivars @context, @lines = context, [] @context.update_details(:formats => [:js, :html]) do include_helpers_from_context diff --git a/actionpack/lib/action_view/render/layouts.rb b/actionpack/lib/action_view/render/layouts.rb index 91a92a833a..0cb688ca77 100644 --- a/actionpack/lib/action_view/render/layouts.rb +++ b/actionpack/lib/action_view/render/layouts.rb @@ -1,8 +1,5 @@ -require 'active_support/core_ext/object/try' - module ActionView module Layouts - # You can think of a layout as a method that is called with a block. _layout_for # returns the contents that are yielded to the layout. If the user calls yield # :some_name, the block, by default, returns content_for(:some_name). If the user @@ -46,7 +43,7 @@ module ActionView # This is the method which actually finds the layout using details in the lookup # context object. If no layout is found, it checkes if at least a layout with # the given name exists across all details before raising the error. - def _find_layout(layout) #:nodoc: + def find_layout(layout) #:nodoc: begin layout =~ /^\// ? with_fallbacks { find_template(layout) } : find_template(layout) diff --git a/actionpack/lib/action_view/render/rendering.rb b/actionpack/lib/action_view/render/rendering.rb index d9ac1f6290..9b5b976727 100644 --- a/actionpack/lib/action_view/render/rendering.rb +++ b/actionpack/lib/action_view/render/rendering.rb @@ -12,14 +12,17 @@ module ActionView # # If no options hash is passed or :update specified, the default is to render a partial and use the second parameter # as the locals hash. - def render(options = {}, locals = {}, &block) #:nodoc: + def render(options = {}, locals = {}, &block) case options when Hash if block_given? content = _render_partial(options.merge(:partial => options[:layout]), &block) safe_concat(content) + elsif options.key?(:partial) + _render_partial(options) else - _render(options) + template = _determine_template(options) + _render_template(template, options[:layout], options) end when :update update_page(&block) @@ -28,31 +31,6 @@ module ActionView end end - # This is the API to render a ViewContext's template from a controller. - def render_template(options, &block) - _evaluate_assigns_and_ivars - - # TODO Layout for partials should be handled here, because inside the - # partial renderer it looks for the layout as a partial. - if options.key?(:partial) && options[:layout] - options[:layout] = _find_layout(options[:layout]) - end - - _render(options, &block) - end - - # This method holds the common render logic for both controllers and - # views rendering stacks. - def _render(options) #:nodoc: - if options.key?(:partial) - _render_partial(options) - else - template = _determine_template(options) - yield template if block_given? - _render_template(template, options[:layout], options) - end - end - # Determine the template to be rendered using the given options. def _determine_template(options) #:nodoc: if options.key?(:inline) @@ -71,8 +49,10 @@ module ActionView # Renders the given template. An string representing the layout can be # supplied as well. def _render_template(template, layout = nil, options = {}) #:nodoc: + self.formats = template.formats + locals = options[:locals] || {} - layout = _find_layout(layout) if layout + layout = find_layout(layout) if layout ActiveSupport::Notifications.instrument("action_view.render_template", :identifier => template.identifier, :layout => layout.try(:identifier)) do @@ -88,6 +68,5 @@ module ActionView content end end - end end diff --git a/actionpack/lib/action_view/template/handlers/rjs.rb b/actionpack/lib/action_view/template/handlers/rjs.rb index 63e7dc0902..128be5077c 100644 --- a/actionpack/lib/action_view/template/handlers/rjs.rb +++ b/actionpack/lib/action_view/template/handlers/rjs.rb @@ -6,8 +6,7 @@ module ActionView self.default_format = Mime::JS def compile(template) - "controller.response.content_type ||= Mime::JS;" + - "update_page do |page|;#{template.source}\nend" + "update_page do |page|;#{template.source}\nend" end def default_format diff --git a/actionpack/lib/action_view/template/text.rb b/actionpack/lib/action_view/template/text.rb index df394b0fb0..269340514c 100644 --- a/actionpack/lib/action_view/template/text.rb +++ b/actionpack/lib/action_view/template/text.rb @@ -1,10 +1,12 @@ module ActionView #:nodoc: class Template class Text < String #:nodoc: - def initialize(string, content_type = nil) + attr_accessor :mime_type + + def initialize(string, mime_type = nil) super(string.to_s) - @content_type = Mime[content_type] || content_type if content_type - @content_type ||= Mime::TEXT + @mime_type = Mime[mime_type] || mime_type if mime_type + @mime_type ||= Mime::TEXT end def identifier @@ -19,12 +21,8 @@ module ActionView #:nodoc: to_s end - def mime_type - @content_type - end - def formats - [@content_type.to_sym] + [@mime_type.to_sym] end def partial? -- cgit v1.2.3 From e484d4ae5684b9ca49b27a844bf48c91c945814e Mon Sep 17 00:00:00 2001 From: Denis Odorcic Date: Thu, 11 Mar 2010 00:47:10 -0500 Subject: Made asset_tag_helper use config.perform_caching instead of ActionController::Base.perform_caching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- .../lib/action_view/helpers/asset_tag_helper.rb | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 0c488b6793..03ae8ce0d8 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -242,12 +242,12 @@ module ActionView # == Caching multiple javascripts into one # # You can also cache multiple javascripts into one file, which requires less HTTP connections to download and can better be - # compressed by gzip (leading to faster transfers). Caching will only happen if ActionController::Base.perform_caching + # compressed by gzip (leading to faster transfers). Caching will only happen if config.perform_caching # is set to true (which is the case by default for the Rails production environment, but not for the development # environment). # # ==== Examples - # javascript_include_tag :all, :cache => true # when ActionController::Base.perform_caching is false => + # javascript_include_tag :all, :cache => true # when config.perform_caching is false => # # # ... @@ -255,15 +255,15 @@ module ActionView # # # - # javascript_include_tag :all, :cache => true # when ActionController::Base.perform_caching is true => + # javascript_include_tag :all, :cache => true # when config.perform_caching is true => # # - # javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when ActionController::Base.perform_caching is false => + # javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when config.perform_caching is false => # # # # - # javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when ActionController::Base.perform_caching is true => + # javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when config.perform_caching is true => # # # The :recursive option is also available for caching: @@ -275,11 +275,11 @@ module ActionView cache = concat || options.delete("cache") recursive = options.delete("recursive") - if concat || (ActionController::Base.perform_caching && cache) + if concat || (config.perform_caching && cache) joined_javascript_name = (cache == true ? "all" : cache) + ".js" joined_javascript_path = File.join(joined_javascript_name[/^#{File::SEPARATOR}/] ? config.assets_dir : config.javascripts_dir, joined_javascript_name) - unless ActionController::Base.perform_caching && File.exists?(joined_javascript_path) + unless config.perform_caching && File.exists?(joined_javascript_path) write_asset_file_contents(joined_javascript_path, compute_javascript_paths(sources, recursive)) end javascript_src_tag(joined_javascript_name, options) @@ -390,25 +390,25 @@ module ActionView # == Caching multiple stylesheets into one # # You can also cache multiple stylesheets into one file, which requires less HTTP connections and can better be - # compressed by gzip (leading to faster transfers). Caching will only happen if ActionController::Base.perform_caching + # compressed by gzip (leading to faster transfers). Caching will only happen if config.perform_caching # is set to true (which is the case by default for the Rails production environment, but not for the development # environment). Examples: # # ==== Examples - # stylesheet_link_tag :all, :cache => true # when ActionController::Base.perform_caching is false => + # stylesheet_link_tag :all, :cache => true # when config.perform_caching is false => # # # # - # stylesheet_link_tag :all, :cache => true # when ActionController::Base.perform_caching is true => + # stylesheet_link_tag :all, :cache => true # when config.perform_caching is true => # # - # stylesheet_link_tag "shop", "cart", "checkout", :cache => "payment" # when ActionController::Base.perform_caching is false => + # stylesheet_link_tag "shop", "cart", "checkout", :cache => "payment" # when config.perform_caching is false => # # # # - # stylesheet_link_tag "shop", "cart", "checkout", :cache => "payment" # when ActionController::Base.perform_caching is true => + # stylesheet_link_tag "shop", "cart", "checkout", :cache => "payment" # when config.perform_caching is true => # # # The :recursive option is also available for caching: @@ -426,11 +426,11 @@ module ActionView cache = concat || options.delete("cache") recursive = options.delete("recursive") - if concat || (ActionController::Base.perform_caching && cache) + if concat || (config.perform_caching && cache) joined_stylesheet_name = (cache == true ? "all" : cache) + ".css" joined_stylesheet_path = File.join(joined_stylesheet_name[/^#{File::SEPARATOR}/] ? config.assets_dir : config.stylesheets_dir, joined_stylesheet_name) - unless ActionController::Base.perform_caching && File.exists?(joined_stylesheet_path) + unless config.perform_caching && File.exists?(joined_stylesheet_path) write_asset_file_contents(joined_stylesheet_path, compute_stylesheet_paths(sources, recursive)) end stylesheet_tag(joined_stylesheet_name, options) -- cgit v1.2.3 From ee4c89627ad5d7b041b88ab4027d3f0d5d582d8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 13 Mar 2010 09:14:09 +0100 Subject: Remove formats setters from render template, speeding up partial and collection renderings. --- actionpack/lib/action_view/render/rendering.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/render/rendering.rb b/actionpack/lib/action_view/render/rendering.rb index 9b5b976727..310efe40e2 100644 --- a/actionpack/lib/action_view/render/rendering.rb +++ b/actionpack/lib/action_view/render/rendering.rb @@ -22,6 +22,7 @@ module ActionView _render_partial(options) else template = _determine_template(options) + self.formats = template.formats _render_template(template, options[:layout], options) end when :update @@ -49,8 +50,6 @@ module ActionView # Renders the given template. An string representing the layout can be # supplied as well. def _render_template(template, layout = nil, options = {}) #:nodoc: - self.formats = template.formats - locals = options[:locals] || {} layout = find_layout(layout) if layout -- cgit v1.2.3 From d252766d03d120513e9295182870fe0ad907454c Mon Sep 17 00:00:00 2001 From: Jeroen van Dijk Date: Sat, 13 Mar 2010 17:30:30 +0100 Subject: Update of block helpers examples in form_helper.rb --- actionpack/lib/action_view/helpers/form_helper.rb | 64 +++++++++++------------ 1 file changed, 32 insertions(+), 32 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 7293145964..6176f1fb06 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -28,7 +28,7 @@ module ActionView # # # Note: a @person variable will have been created in the controller. # # For example: @person = Person.new - # <% form_for :person, @person, :url => { :action => "create" } do |f| %> + # <%= form_for :person, @person, :url => { :action => "create" } do |f| %> # <%= f.text_field :first_name %> # <%= f.text_field :last_name %> # <%= submit_tag 'Create' %> @@ -44,7 +44,7 @@ module ActionView # # If you are using a partial for your form fields, you can use this shortcut: # - # <% form_for :person, @person, :url => { :action => "create" } do |f| %> + # <%= form_for :person, @person, :url => { :action => "create" } do |f| %> # <%= render :partial => f %> # <%= submit_tag 'Create' %> # <% end %> @@ -102,7 +102,7 @@ module ActionView # Rails provides succinct resource-oriented form generation with +form_for+ # like this: # - # <% form_for @offer do |f| %> + # <%= form_for @offer do |f| %> # <%= f.label :version, 'Version' %>: # <%= f.text_field :version %>
    # <%= f.label :author, 'Author' %>: @@ -119,7 +119,7 @@ module ActionView # The generic way to call +form_for+ yields a form builder around a # model: # - # <% form_for :person, :url => { :action => "update" } do |f| %> + # <%= form_for :person, :url => { :action => "update" } do |f| %> # <%= f.error_messages %> # First name: <%= f.text_field :first_name %>
    # Last name : <%= f.text_field :last_name %>
    @@ -143,7 +143,7 @@ module ActionView # If the instance variable is not @person you can pass the actual # record as the second argument: # - # <% form_for :person, person, :url => { :action => "update" } do |f| %> + # <%= form_for :person, person, :url => { :action => "update" } do |f| %> # ... # <% end %> # @@ -175,7 +175,7 @@ module ActionView # possible to use both the stand-alone FormHelper methods and methods # from FormTagHelper. For example: # - # <% form_for :person, @person, :url => { :action => "update" } do |f| %> + # <%= form_for :person, @person, :url => { :action => "update" } do |f| %> # First name: <%= f.text_field :first_name %> # Last name : <%= f.text_field :last_name %> # Biography : <%= text_area :person, :biography %> @@ -195,37 +195,37 @@ module ActionView # # For example, if @post is an existing record you want to edit # - # <% form_for @post do |f| %> + # <%= form_for @post do |f| %> # ... # <% end %> # # is equivalent to something like: # - # <% form_for :post, @post, :url => post_path(@post), :html => { :method => :put, :class => "edit_post", :id => "edit_post_45" } do |f| %> + # <%= form_for :post, @post, :url => post_path(@post), :html => { :method => :put, :class => "edit_post", :id => "edit_post_45" } do |f| %> # ... # <% end %> # # And for new records # - # <% form_for(Post.new) do |f| %> + # <%= form_for(Post.new) do |f| %> # ... # <% end %> # # expands to # - # <% form_for :post, Post.new, :url => posts_path, :html => { :class => "new_post", :id => "new_post" } do |f| %> + # <%= form_for :post, Post.new, :url => posts_path, :html => { :class => "new_post", :id => "new_post" } do |f| %> # ... # <% end %> # # You can also overwrite the individual conventions, like this: # - # <% form_for(@post, :url => super_post_path(@post)) do |f| %> + # <%= form_for(@post, :url => super_post_path(@post)) do |f| %> # ... # <% end %> # # And for namespaced routes, like +admin_post_url+: # - # <% form_for([:admin, @post]) do |f| %> + # <%= form_for([:admin, @post]) do |f| %> # ... # <% end %> # @@ -243,7 +243,7 @@ module ActionView # # Example: # - # <% form_for(:post, @post, :remote => true, :html => { :id => 'create-post', :method => :put }) do |f| %> + # <%= form_for(:post, @post, :remote => true, :html => { :id => 'create-post', :method => :put }) do |f| %> # ... # <% end %> # @@ -263,7 +263,7 @@ module ActionView # custom builder. For example, let's say you made a helper to # automatically add labels to form inputs. # - # <% form_for :person, @person, :url => { :action => "update" }, :builder => LabellingFormBuilder do |f| %> + # <%= form_for :person, @person, :url => { :action => "update" }, :builder => LabellingFormBuilder do |f| %> # <%= f.text_field :first_name %> # <%= f.text_field :last_name %> # <%= text_area :person, :biography %> @@ -340,11 +340,11 @@ module ActionView # # === Generic Examples # - # <% form_for @person, :url => { :action => "update" } do |person_form| %> + # <%= form_for @person, :url => { :action => "update" } do |person_form| %> # First name: <%= person_form.text_field :first_name %> # Last name : <%= person_form.text_field :last_name %> # - # <% fields_for @person.permission do |permission_fields| %> + # <%= fields_for @person.permission do |permission_fields| %> # Admin? : <%= permission_fields.check_box :admin %> # <% end %> # <% end %> @@ -352,13 +352,13 @@ module ActionView # ...or if you have an object that needs to be represented as a different # parameter, like a Client that acts as a Person: # - # <% fields_for :person, @client do |permission_fields| %> + # <%= fields_for :person, @client do |permission_fields| %> # Admin?: <%= permission_fields.check_box :admin %> # <% end %> # # ...or if you don't have an object, just a name of the parameter: # - # <% fields_for :person do |permission_fields| %> + # <%= fields_for :person do |permission_fields| %> # Admin?: <%= permission_fields.check_box :admin %> # <% end %> # @@ -402,9 +402,9 @@ module ActionView # # This model can now be used with a nested fields_for, like so: # - # <% form_for @person, :url => { :action => "update" } do |person_form| %> + # <%= form_for @person, :url => { :action => "update" } do |person_form| %> # ... - # <% person_form.fields_for :address do |address_fields| %> + # <%= person_form.fields_for :address do |address_fields| %> # Street : <%= address_fields.text_field :street %> # Zip code: <%= address_fields.text_field :zip_code %> # <% end %> @@ -431,9 +431,9 @@ module ActionView # with a value that evaluates to +true+, you will destroy the associated # model (eg. 1, '1', true, or 'true'): # - # <% form_for @person, :url => { :action => "update" } do |person_form| %> + # <%= form_for @person, :url => { :action => "update" } do |person_form| %> # ... - # <% person_form.fields_for :address do |address_fields| %> + # <%= person_form.fields_for :address do |address_fields| %> # ... # Delete: <%= address_fields.check_box :_destroy %> # <% end %> @@ -459,9 +459,9 @@ module ActionView # the nested fields_for call will be repeated for each instance in the # collection: # - # <% form_for @person, :url => { :action => "update" } do |person_form| %> + # <%= form_for @person, :url => { :action => "update" } do |person_form| %> # ... - # <% person_form.fields_for :projects do |project_fields| %> + # <%= person_form.fields_for :projects do |project_fields| %> # <% if project_fields.object.active? %> # Name: <%= project_fields.text_field :name %> # <% end %> @@ -470,11 +470,11 @@ module ActionView # # It's also possible to specify the instance to be used: # - # <% form_for @person, :url => { :action => "update" } do |person_form| %> + # <%= form_for @person, :url => { :action => "update" } do |person_form| %> # ... # <% @person.projects.each do |project| %> # <% if project.active? %> - # <% person_form.fields_for :projects, project do |project_fields| %> + # <%= person_form.fields_for :projects, project do |project_fields| %> # Name: <%= project_fields.text_field :name %> # <% end %> # <% end %> @@ -483,9 +483,9 @@ module ActionView # # Or a collection to be used: # - # <% form_for @person, :url => { :action => "update" } do |person_form| %> + # <%= form_for @person, :url => { :action => "update" } do |person_form| %> # ... - # <% person_form.fields_for :projects, @active_projects do |project_fields| %> + # <%= person_form.fields_for :projects, @active_projects do |project_fields| %> # Name: <%= project_fields.text_field :name %> # <% end %> # <% end %> @@ -512,9 +512,9 @@ module ActionView # parameter with a value that evaluates to +true+ # (eg. 1, '1', true, or 'true'): # - # <% form_for @person, :url => { :action => "update" } do |person_form| %> + # <%= form_for @person, :url => { :action => "update" } do |person_form| %> # ... - # <% person_form.fields_for :projects do |project_fields| %> + # <%= person_form.fields_for :projects do |project_fields| %> # Delete: <%= project_fields.check_box :_destroy %> # <% end %> # <% end %> @@ -725,7 +725,7 @@ module ActionView # Unfortunately that workaround does not work when the check box goes # within an array-like parameter, as in # - # <% fields_for "project[invoice_attributes][]", invoice, :index => nil do |form| %> + # <%= fields_for "project[invoice_attributes][]", invoice, :index => nil do |form| %> # <%= form.check_box :paid %> # ... # <% end %> @@ -1115,7 +1115,7 @@ module ActionView # Add the submit button for the given form. When no value is given, it checks # if the object is a new resource or not to create the proper label: # - # <% form_for @post do |f| %> + # <%= form_for @post do |f| %> # <%= f.submit %> # <% end %> # -- cgit v1.2.3 From 4ba334c0f4dac35b0c02cf3c4cca47d328283009 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 13 Mar 2010 21:28:34 +0100 Subject: Ensure controller filters are executed before stuff starts to happen. --- actionpack/lib/action_controller/base.rb | 8 ++++++-- actionpack/lib/action_controller/metal/rendering.rb | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index fcd3cb9bd3..ad2b68af21 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -2,7 +2,6 @@ module ActionController class Base < Metal abstract! - include AbstractController::Callbacks include AbstractController::Layouts include AbstractController::Translation @@ -23,6 +22,7 @@ module ActionController # Rails 2.x compatibility include ActionController::Compatibility + include ActionController::ImplicitRender include ActionController::Cookies include ActionController::Flash @@ -36,8 +36,12 @@ module ActionController # Add instrumentations hooks at the bottom, to ensure they instrument # all the methods properly. include ActionController::Instrumentation - include ImplicitRender + # Before callbacks should also be executed the earliest as possible, so + # also include them at the bottom. + include AbstractController::Callbacks + + # The same with rescue, append it at the end to wrap as much as possible. include ActionController::Rescue def self.inherited(klass) diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb index 2167fe9a32..86bb810947 100644 --- a/actionpack/lib/action_controller/metal/rendering.rb +++ b/actionpack/lib/action_controller/metal/rendering.rb @@ -6,7 +6,7 @@ module ActionController include AbstractController::Rendering # Before processing, set the request formats in current controller formats. - def process(*) #:nodoc: + def process_action(*) #:nodoc: self.formats = request.formats.map { |x| x.to_sym } super end -- cgit v1.2.3 From 3da9a08a7367eb389ddc03159bfbe5e9a8416e20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 14 Mar 2010 10:25:29 +0100 Subject: Optimize DetailsKey generation. --- actionpack/lib/action_view/lookup_context.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/lookup_context.rb b/actionpack/lib/action_view/lookup_context.rb index 22ab076b59..8eb17bf8f1 100644 --- a/actionpack/lib/action_view/lookup_context.rb +++ b/actionpack/lib/action_view/lookup_context.rb @@ -38,17 +38,18 @@ module ActionView register_detail(:locale) { [I18n.locale] } class DetailsKey #:nodoc: - attr_reader :details alias :eql? :equal? + alias :object_hash :hash + attr_reader :hash @details_keys = Hash.new def self.get(details) - @details_keys[details] ||= new(details) + @details_keys[details] ||= new end - def initialize(details) - @details, @hash = details, details.hash + def initialize + @hash = object_hash end end -- cgit v1.2.3 From beeb02076a0b7a8bce59555cd486b96c59e231f0 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 14 Mar 2010 13:11:07 -0300 Subject: Making escaped things more readable --- actionpack/lib/action_view/helpers/active_model_helper.rb | 2 +- actionpack/lib/action_view/helpers/tag_helper.rb | 2 +- actionpack/lib/action_view/helpers/url_helper.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/active_model_helper.rb b/actionpack/lib/action_view/helpers/active_model_helper.rb index 4e12cdab54..e3db2923f7 100644 --- a/actionpack/lib/action_view/helpers/active_model_helper.rb +++ b/actionpack/lib/action_view/helpers/active_model_helper.rb @@ -129,7 +129,7 @@ module ActionView if (obj = (object.respond_to?(:errors) ? object : instance_variable_get("@#{object}"))) && (errors = obj.errors[method]) content_tag("div", - (options[:prepend_text].html_safe << errors.first).safe_concat(options[:append_text]), + "#{options[:prepend_text]}#{ERB::Util.h(errors.first)}#{options[:append_text]}".html_safe, :class => options[:css_class] ) else diff --git a/actionpack/lib/action_view/helpers/tag_helper.rb b/actionpack/lib/action_view/helpers/tag_helper.rb index d9d2588a2a..bbbc1f0981 100644 --- a/actionpack/lib/action_view/helpers/tag_helper.rb +++ b/actionpack/lib/action_view/helpers/tag_helper.rb @@ -109,7 +109,7 @@ module ActionView def content_tag_string(name, content, options, escape = true) tag_options = tag_options(options, escape) if options - ("<#{name}#{tag_options}>".html_safe << content.to_s).safe_concat("") + "<#{name}#{tag_options}>#{ERB::Util.h(content)}".html_safe end def tag_options(options, escape = true) diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 148f2868e9..14d59034f1 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -224,7 +224,7 @@ module ActionView end href_attr = "href=\"#{url}\"" unless href - ("".html_safe << (name || url)).safe_concat("") + "#{ERB::Util.h(name || url)}".html_safe end end -- cgit v1.2.3 From 16572fd46e189d80c6be7d499e687fe129053a2c Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 14 Mar 2010 18:55:13 -0700 Subject: read_ and write_fragment cache preserve html safety yet cache strings only --- actionpack/lib/action_controller/caching/fragments.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/caching/fragments.rb b/actionpack/lib/action_controller/caching/fragments.rb index bb5ff95a67..841e64ecaf 100644 --- a/actionpack/lib/action_controller/caching/fragments.rb +++ b/actionpack/lib/action_controller/caching/fragments.rb @@ -41,9 +41,7 @@ module ActionController #:nodoc: else pos = buffer.length block.call - content = buffer[pos..-1] - content = content.as_str if content.respond_to?(:as_str) - write_fragment(name, content, options) + write_fragment(name, buffer[pos..-1], options) end else block.call @@ -53,9 +51,10 @@ module ActionController #:nodoc: # Writes content to the location signified by key (see expire_fragment for acceptable formats) def write_fragment(key, content, options = nil) return content unless cache_configured? - key = fragment_cache_key(key) + key = fragment_cache_key(key) instrument_fragment_cache :write_fragment, key do + content = content.html_safe.as_str if content.respond_to?(:html_safe) cache_store.write(key, content, options) end content @@ -64,10 +63,11 @@ module ActionController #:nodoc: # Reads a cached fragment from the location signified by key (see expire_fragment for acceptable formats) def read_fragment(key, options = nil) return unless cache_configured? - key = fragment_cache_key(key) + key = fragment_cache_key(key) instrument_fragment_cache :read_fragment, key do - cache_store.read(key, options) + result = cache_store.read(key, options) + result.respond_to?(:html_safe) ? result.html_safe : result end end -- cgit v1.2.3 From 96bc6bcfee704701de1a9c4c3c6a7c265610d34d Mon Sep 17 00:00:00 2001 From: Andrew White Date: Mon, 15 Mar 2010 09:45:29 -0500 Subject: Don't force singularization of singleton resource names, e.g. /preferences [#4089 state:resolved] Signed-off-by: Joshua Peek --- actionpack/lib/action_dispatch/routing/mapper.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 0b7b09ee7a..f9b27a5a03 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -362,11 +362,11 @@ module ActionDispatch attr_reader :plural, :singular, :options def initialize(entities, options = {}) - entities = entities.to_s + @name = entities.to_s @options = options - @plural = entities.pluralize - @singular = entities.singularize + @plural = @name.pluralize + @singular = @name.singularize end def default_actions @@ -393,7 +393,7 @@ module ActionDispatch end def name - options[:as] || plural + options[:as] || @name end def controller @@ -438,8 +438,8 @@ module ActionDispatch end end - def name - options[:as] || singular + def member_name + name end end @@ -468,8 +468,8 @@ module ActionDispatch post :create if resource.actions.include?(:create) put :update if resource.actions.include?(:update) delete :destroy if resource.actions.include?(:destroy) - get :new, :as => resource.singular if resource.actions.include?(:new) - get :edit, :as => resource.singular if resource.actions.include?(:edit) + get :new, :as => resource.name if resource.actions.include?(:new) + get :edit, :as => resource.name if resource.actions.include?(:edit) end end -- cgit v1.2.3 From c937da9e2fc14f74fb11d1ce605479c033ca29ee Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 15 Mar 2010 11:17:18 -0700 Subject: to_str works here --- actionpack/lib/action_controller/caching/fragments.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/caching/fragments.rb b/actionpack/lib/action_controller/caching/fragments.rb index 841e64ecaf..89787727bd 100644 --- a/actionpack/lib/action_controller/caching/fragments.rb +++ b/actionpack/lib/action_controller/caching/fragments.rb @@ -54,7 +54,7 @@ module ActionController #:nodoc: key = fragment_cache_key(key) instrument_fragment_cache :write_fragment, key do - content = content.html_safe.as_str if content.respond_to?(:html_safe) + content = content.html_safe.to_str if content.respond_to?(:html_safe) cache_store.write(key, content, options) end content -- cgit v1.2.3 From a594a22267bfd3346e00923742c4aa7edad0cef7 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 15 Mar 2010 18:29:21 +0100 Subject: with_output_buffer cannot assume there's an output_buffer [#4182 state:committed] Signed-off-by: Jeremy Kemper --- actionpack/lib/action_view/helpers/capture_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb index 75fc2fddeb..03c7ba5a87 100644 --- a/actionpack/lib/action_view/helpers/capture_helper.rb +++ b/actionpack/lib/action_view/helpers/capture_helper.rb @@ -140,7 +140,7 @@ module ActionView def with_output_buffer(buf = nil) #:nodoc: unless buf buf = ActionView::OutputBuffer.new - buf.force_encoding(output_buffer.encoding) if buf.respond_to?(:force_encoding) + buf.force_encoding(output_buffer.encoding) if output_buffer && buf.respond_to?(:force_encoding) end self.output_buffer, old_buffer = buf, output_buffer yield -- cgit v1.2.3 From 9de83050d3a4b260d4aeb5d09ec4eb64f913ba64 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Mon, 15 Mar 2010 11:58:05 -0700 Subject: Add deprecation notices for <% %>. * The approach is to compile <% %> into a method call that checks whether the value returned from a block is a String. If it is, it concats to the buffer and prints a deprecation warning. * <%= %> uses exactly the same logic to compile the template, which first checks to see whether it's compiling a block. * This should have no impact on other uses of block in templates. For instance, in <% [1,2,3].each do |i| %><%= i %><% end %>, the call to each returns an Array, not a String, so the result is not concatenated * In two cases (#capture and #cache), a String can be returned that should *never* be concatenated. We have temporarily created a String subclass called NonConcattingString which behaves (and is serialized) identically to String, but is not concatenated by the code that handles deprecated <% %> block helpers. Once we remove support for <% %> block helpers, we can remove NonConcattingString. --- .../lib/action_controller/caching/fragments.rb | 16 ++++--- actionpack/lib/action_view/base.rb | 3 ++ actionpack/lib/action_view/helpers/cache_helper.rb | 2 +- .../lib/action_view/helpers/capture_helper.rb | 28 ++++++------ .../helpers/deprecated_block_helpers.rb | 52 ---------------------- .../lib/action_view/helpers/prototype_helper.rb | 4 ++ actionpack/lib/action_view/render/rendering.rb | 3 +- .../lib/action_view/template/handlers/erb.rb | 19 +++++++- 8 files changed, 53 insertions(+), 74 deletions(-) delete mode 100644 actionpack/lib/action_view/helpers/deprecated_block_helpers.rb (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/caching/fragments.rb b/actionpack/lib/action_controller/caching/fragments.rb index 89787727bd..a07fe2b255 100644 --- a/actionpack/lib/action_controller/caching/fragments.rb +++ b/actionpack/lib/action_controller/caching/fragments.rb @@ -34,17 +34,23 @@ module ActionController #:nodoc: ActiveSupport::Cache.expand_cache_key(key.is_a?(Hash) ? url_for(key).split("://").last : key, :views) end - def fragment_for(buffer, name = {}, options = nil, &block) #:nodoc: + def fragment_for(name = {}, options = nil, &block) #:nodoc: if perform_caching if fragment_exist?(name, options) - buffer.safe_concat(read_fragment(name, options)) + read_fragment(name, options) else + # VIEW TODO: Make #capture usable outside of ERB + # This dance is needed because Builder can't use capture + buffer = view_context.output_buffer pos = buffer.length - block.call - write_fragment(name, buffer[pos..-1], options) + yield + fragment = buffer[pos..-1] + write_fragment(name, fragment, options) + ActionView::NonConcattingString.new(fragment) end else - block.call + ret = yield + ActiveSupport::SafeBuffer.new(ret) if ret.is_a?(String) end end diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index feaf45c333..3920d8593f 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -3,6 +3,9 @@ require 'active_support/core_ext/module/delegation' require 'active_support/core_ext/class/attribute' module ActionView #:nodoc: + class NonConcattingString < ActiveSupport::SafeBuffer + end + class ActionViewError < StandardError #:nodoc: end diff --git a/actionpack/lib/action_view/helpers/cache_helper.rb b/actionpack/lib/action_view/helpers/cache_helper.rb index d5cc14b29a..3729d7daa8 100644 --- a/actionpack/lib/action_view/helpers/cache_helper.rb +++ b/actionpack/lib/action_view/helpers/cache_helper.rb @@ -32,7 +32,7 @@ module ActionView # Topics listed alphabetically # <% end %> def cache(name = {}, options = nil, &block) - controller.fragment_for(output_buffer, name, options, &block) + controller.fragment_for(name, options, &block) end end end diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb index 03c7ba5a87..b64dc1533f 100644 --- a/actionpack/lib/action_view/helpers/capture_helper.rb +++ b/actionpack/lib/action_view/helpers/capture_helper.rb @@ -2,22 +2,22 @@ module ActionView module Helpers # CaptureHelper exposes methods to let you extract generated markup which # can be used in other parts of a template or layout file. - # It provides a method to capture blocks into variables through capture and + # It provides a method to capture blocks into variables through capture and # a way to capture a block of markup for use in a layout through content_for. module CaptureHelper - # The capture method allows you to extract part of a template into a - # variable. You can then use this variable anywhere in your templates or layout. - # + # The capture method allows you to extract part of a template into a + # variable. You can then use this variable anywhere in your templates or layout. + # # ==== Examples # The capture method can be used in ERb templates... - # + # # <% @greeting = capture do %> # Welcome to my shiny new web page! The date and time is # <%= Time.now %> # <% end %> # # ...and Builder (RXML) templates. - # + # # @timestamp = capture do # "The current timestamp is #{Time.now}." # end @@ -33,15 +33,17 @@ module ActionView def capture(*args) value = nil buffer = with_output_buffer { value = yield *args } - buffer.presence || value + if string = buffer.presence || value and string.is_a?(String) + NonConcattingString.new(string) + end end # Calling content_for stores a block of markup in an identifier for later use. # You can make subsequent calls to the stored content in other templates or the layout # by passing the identifier as an argument to yield. - # + # # ==== Examples - # + # # <% content_for :not_authorized do %> # alert('You are not authorized to do that!') # <% end %> @@ -92,7 +94,7 @@ module ActionView # <% end %> # # <%# Add some other content, or use a different template: %> - # + # # <% content_for :navigation do %> #
  • <%= link_to 'Login', :action => 'login' %>
  • # <% end %> @@ -109,13 +111,13 @@ module ActionView # for elements that will be fragment cached. def content_for(name, content = nil, &block) content = capture(&block) if block_given? - return @_content_for[name] << content if content - @_content_for[name] + @_content_for[name] << content if content + @_content_for[name] unless content end # content_for? simply checks whether any content has been captured yet using content_for # Useful to render parts of your layout differently based on what is in your views. - # + # # ==== Examples # # Perhaps you will use different css in you layout if no content_for :right_column diff --git a/actionpack/lib/action_view/helpers/deprecated_block_helpers.rb b/actionpack/lib/action_view/helpers/deprecated_block_helpers.rb deleted file mode 100644 index 3d0657e873..0000000000 --- a/actionpack/lib/action_view/helpers/deprecated_block_helpers.rb +++ /dev/null @@ -1,52 +0,0 @@ -module ActionView - module Helpers - module DeprecatedBlockHelpers - extend ActiveSupport::Concern - - include ActionView::Helpers::TagHelper - include ActionView::Helpers::TextHelper - include ActionView::Helpers::JavaScriptHelper - include ActionView::Helpers::FormHelper - - def content_tag(*, &block) - block_called_from_erb?(block) ? safe_concat(super) : super - end - - def javascript_tag(*, &block) - block_called_from_erb?(block) ? safe_concat(super) : super - end - - def form_for(*, &block) - block_called_from_erb?(block) ? safe_concat(super) : super - end - - def form_tag(*, &block) - block_called_from_erb?(block) ? safe_concat(super) : super - end - - def fields_for(*, &block) - block_called_from_erb?(block) ? safe_concat(super) : super - end - - def field_set_tag(*, &block) - block_called_from_erb?(block) ? safe_concat(super) : super - end - - BLOCK_CALLED_FROM_ERB = 'defined? __in_erb_template' - - if RUBY_VERSION < '1.9.0' - # Check whether we're called from an erb template. - # We'd return a string in any other case, but erb <%= ... %> - # can't take an <% end %> later on, so we have to use <% ... %> - # and implicitly concat. - def block_called_from_erb?(block) - block && eval(BLOCK_CALLED_FROM_ERB, block) - end - else - def block_called_from_erb?(block) - block && eval(BLOCK_CALLED_FROM_ERB, block.binding) - end - end - end - end -end \ No newline at end of file diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index e58fdf81fb..e46ca53275 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -689,6 +689,10 @@ module ActionView @generator << root if root end + def is_a?(klass) + klass == JavaScriptProxy + end + private def method_missing(method, *arguments, &block) if method.to_s =~ /(.*)=$/ diff --git a/actionpack/lib/action_view/render/rendering.rb b/actionpack/lib/action_view/render/rendering.rb index 310efe40e2..d8dfd5077b 100644 --- a/actionpack/lib/action_view/render/rendering.rb +++ b/actionpack/lib/action_view/render/rendering.rb @@ -16,8 +16,7 @@ module ActionView case options when Hash if block_given? - content = _render_partial(options.merge(:partial => options[:layout]), &block) - safe_concat(content) + _render_partial(options.merge(:partial => options[:layout]), &block) elsif options.key?(:partial) _render_partial(options) else diff --git a/actionpack/lib/action_view/template/handlers/erb.rb b/actionpack/lib/action_view/template/handlers/erb.rb index ac5902cc0e..705c2bf82e 100644 --- a/actionpack/lib/action_view/template/handlers/erb.rb +++ b/actionpack/lib/action_view/template/handlers/erb.rb @@ -8,6 +8,13 @@ module ActionView super(value.to_s) end alias :append= :<< + + def append_if_string=(value) + if value.is_a?(String) && !value.is_a?(NonConcattingString) + ActiveSupport::Deprecation.warn("<% %> style block helpers are deprecated. Please use <%= %>", caller) + self << value + end + end end module Template::Handlers @@ -21,14 +28,24 @@ module ActionView src << "@output_buffer.safe_concat('" << escape_text(text) << "');" end + BLOCK_EXPR = /(do|\{)(\s*\|[^|]*\|)?\s*\Z/ + def add_expr_literal(src, code) - if code =~ /(do|\{)(\s*\|[^|]*\|)?\s*\Z/ + if code =~ BLOCK_EXPR src << '@output_buffer.append= ' << code else src << '@output_buffer.append= (' << code << ');' end end + def add_stmt(src, code) + if code =~ BLOCK_EXPR + src << '@output_buffer.append_if_string= ' << code + else + super + end + end + def add_expr_escaped(src, code) src << '@output_buffer.append= ' << escaped_expr(code) << ';' end -- cgit v1.2.3 From 5913dd478150710fc0b72a0568f68e13c958d6bc Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 15 Mar 2010 15:54:37 -0700 Subject: Reinstate old default_url_options method signature --- actionpack/lib/action_dispatch/routing/url_for.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/url_for.rb b/actionpack/lib/action_dispatch/routing/url_for.rb index ec78f53fa6..9a64979074 100644 --- a/actionpack/lib/action_dispatch/routing/url_for.rb +++ b/actionpack/lib/action_dispatch/routing/url_for.rb @@ -100,7 +100,7 @@ module ActionDispatch end def url_options - default_url_options + default_url_options({}) end # Generate a url based on the options provided, default_url_options and the -- cgit v1.2.3 From 1f5e2f2bad3c33ec52312a1700bacf06a71875a5 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 15 Mar 2010 16:49:03 -0700 Subject: Revert "Reinstate old default_url_options method signature" This reverts commit 5913dd478150710fc0b72a0568f68e13c958d6bc. --- actionpack/lib/action_dispatch/routing/url_for.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/url_for.rb b/actionpack/lib/action_dispatch/routing/url_for.rb index 9a64979074..ec78f53fa6 100644 --- a/actionpack/lib/action_dispatch/routing/url_for.rb +++ b/actionpack/lib/action_dispatch/routing/url_for.rb @@ -100,7 +100,7 @@ module ActionDispatch end def url_options - default_url_options({}) + default_url_options end # Generate a url based on the options provided, default_url_options and the -- cgit v1.2.3 From 8dd731bc502a07f4fb76eb2706a1f3bca479ef63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 16 Mar 2010 02:08:34 +0100 Subject: Move more normalization up to the lookup context, so it does not have to repeat in every resolver. --- actionpack/lib/action_view/lookup_context.rb | 36 ++++++++++++++++++++----- actionpack/lib/action_view/template/resolver.rb | 24 +---------------- 2 files changed, 31 insertions(+), 29 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/lookup_context.rb b/actionpack/lib/action_view/lookup_context.rb index 8eb17bf8f1..598007c7a4 100644 --- a/actionpack/lib/action_view/lookup_context.rb +++ b/actionpack/lib/action_view/lookup_context.rb @@ -15,12 +15,10 @@ module ActionView def self.register_detail(name, options = {}, &block) self.registered_details << name - Setters.send :define_method, :"_#{name}_defaults", &block Setters.module_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{name}=(value) value = Array(value.presence || _#{name}_defaults) - #{"value << nil unless value.include?(nil)" unless options[:allow_nil] == false} unless value == @details[:#{name}] @details_key, @details = nil, @details.merge(:#{name} => value) @@ -69,16 +67,16 @@ module ActionView end def find(name, prefix = nil, partial = false) - @view_paths.find(name, prefix, partial, details, details_key) + @view_paths.find(*args_for_lookup(name, prefix, partial)) end alias :find_template :find def find_all(name, prefix = nil, partial = false) - @view_paths.find_all(name, prefix, partial, details, details_key) + @view_paths.find_all(*args_for_lookup(name, prefix, partial)) end def exists?(name, prefix = nil, partial = false) - @view_paths.exists?(name, prefix, partial, details, details_key) + @view_paths.exists?(*args_for_lookup(name, prefix, partial)) end alias :template_exists? :exists? @@ -94,6 +92,32 @@ module ActionView ensure added_resolvers.times { view_paths.pop } end + + protected + + def args_for_lookup(name, prefix, partial) #:nodoc: + name, prefix = normalize_name(name, prefix) + details_key = self.details_key + details = self.details.merge(:handlers => default_handlers) + [name, prefix, partial || false, details, details_key] + end + + # Support legacy foo.erb names even though we now ignore .erb + # as well as incorrectly putting part of the path in the template + # name instead of the prefix. + def normalize_name(name, prefix) #:nodoc: + name = name.to_s.gsub(handlers_regexp, '') + parts = name.split('/') + return parts.pop, [prefix, *parts].compact.join("/") + end + + def default_handlers #:nodoc: + @detault_handlers ||= Template::Handlers.extensions + end + + def handlers_regexp #:nodoc: + @handlers_regexp ||= /\.(?:#{default_handlers.join('|')})$/ + end end module Details @@ -113,7 +137,7 @@ module ActionView end # Overload formats= to reject [:"*/*"] values. - def formats=(value, freeze=true) + def formats=(value) value = nil if value == [:"*/*"] super(value) end diff --git a/actionpack/lib/action_view/template/resolver.rb b/actionpack/lib/action_view/template/resolver.rb index a43597e728..ee13707327 100644 --- a/actionpack/lib/action_view/template/resolver.rb +++ b/actionpack/lib/action_view/template/resolver.rb @@ -14,15 +14,8 @@ module ActionView @cached.clear end - def find(*args) - find_all(*args).first - end - # Normalizes the arguments and passes it on to find_template. def find_all(name, prefix=nil, partial=false, details={}, key=nil) - name, prefix = normalize_name(name, prefix) - details = details.merge(:handlers => default_handlers) - cached(key, prefix, name, partial) do find_templates(name, prefix, partial, details) end @@ -34,10 +27,6 @@ module ActionView @caching ||= !defined?(Rails.application) || Rails.application.config.cache_classes end - def default_handlers - Template::Handlers.extensions + [nil] - end - # This is what child classes implement. No defaults are needed # because Resolver guarantees that the arguments are present and # normalized. @@ -45,17 +34,6 @@ module ActionView raise NotImplementedError end - # Support legacy foo.erb names even though we now ignore .erb - # as well as incorrectly putting part of the path in the template - # name instead of the prefix. - def normalize_name(name, prefix) - handlers = Template::Handlers.extensions.join('|') - name = name.to_s.gsub(/\.(?:#{handlers})$/, '') - - parts = name.split('/') - return parts.pop, [prefix, *parts].compact.join("/") - end - def cached(key, prefix, name, partial) return yield unless key && caching? scope = @cached[key][prefix][name] @@ -93,7 +71,7 @@ module ActionView query = File.join(@path, path) exts.each do |ext| - query << '{' << ext.map {|e| e && ".#{e}" }.join(',') << '}' + query << '{' << ext.map {|e| e && ".#{e}" }.join(',') << ',}' end Dir[query].reject { |p| File.directory?(p) }.map do |p| -- cgit v1.2.3 From 2a50eabf4576580dff9b43c3d830cd78e8fbb353 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 15 Mar 2010 19:26:58 -0700 Subject: Integration test url options should account for :protocol not just https? --- actionpack/lib/action_dispatch/testing/integration.rb | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 0aff4250c1..31067e56b4 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -177,14 +177,8 @@ module ActionDispatch reset! end - def url_options - opts = super.reverse_merge( - :host => host, - :protocol => https? ? "https" : "http" - ) - - opts.merge!(:port => 443) if !opts.key?(:port) && https? - opts + def default_url_options + { :host => host, :protocol => https? ? "https" : "http" } end # Resets the instance. This can be used to reset the state information -- cgit v1.2.3 From 9e1e95f70af3c566190f47ee7a52fd49f785ec12 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 15 Mar 2010 23:05:12 -0700 Subject: link_to_remote -> link_to :remote => true --- actionpack/lib/action_view/helpers/capture_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb index b64dc1533f..42a67756e4 100644 --- a/actionpack/lib/action_view/helpers/capture_helper.rb +++ b/actionpack/lib/action_view/helpers/capture_helper.rb @@ -77,7 +77,7 @@ module ActionView # # Then, in another view, you could to do something like this: # - # <%= link_to_remote 'Logout', :action => 'logout' %> + # <%= link_to 'Logout', :action => 'logout', :remote => true %> # # <% content_for :script do %> # <%= javascript_include_tag :defaults %> -- cgit v1.2.3 From b3b6ff48dff49ebbdab0a53f576bc0572116767f Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 15 Mar 2010 23:26:48 -0700 Subject: Fix link_to with block --- actionpack/lib/action_view/helpers/url_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 14d59034f1..94f1cecade 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -206,7 +206,7 @@ module ActionView if block_given? options = args.first || {} html_options = args.second - safe_concat(link_to(capture(&block), options, html_options)) + link_to(capture(&block), options, html_options) else name = args[0] options = args[1] || {} -- cgit v1.2.3 From 748c78ffc8b11a608745290e7d68bdf63720cfab Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 15 Mar 2010 23:48:32 -0700 Subject: RJS may cache an array --- actionpack/lib/action_controller/caching/fragments.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/caching/fragments.rb b/actionpack/lib/action_controller/caching/fragments.rb index a07fe2b255..19bf3ddd3b 100644 --- a/actionpack/lib/action_controller/caching/fragments.rb +++ b/actionpack/lib/action_controller/caching/fragments.rb @@ -46,7 +46,7 @@ module ActionController #:nodoc: yield fragment = buffer[pos..-1] write_fragment(name, fragment, options) - ActionView::NonConcattingString.new(fragment) + fragment.is_a?(String) ? ActionView::NonConcattingString.new(fragment) : fragment end else ret = yield -- cgit v1.2.3 From e13c179499f227071cbe829221877e1c0d03c0b1 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 8 Mar 2010 19:55:57 -0200 Subject: Change array entries to safe doesn't worth then the array is joined as a string losing the safe property of his entries [#4134 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_view/helpers/translation_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/translation_helper.rb b/actionpack/lib/action_view/helpers/translation_helper.rb index 8a89ee58a0..f996762d6f 100644 --- a/actionpack/lib/action_view/helpers/translation_helper.rb +++ b/actionpack/lib/action_view/helpers/translation_helper.rb @@ -13,7 +13,7 @@ module ActionView def translate(key, options = {}) options[:raise] = true translation = I18n.translate(scope_key_by_partial(key), options) - translation.is_a?(Array) ? translation.map { |entry| entry.html_safe } : translation.html_safe + translation.respond_to?(:html_safe) ? translation.html_safe : translation rescue I18n::MissingTranslationData => e keys = I18n.normalize_keys(e.locale, e.key, e.options[:scope]) content_tag('span', keys.join(', '), :class => 'translation_missing') -- cgit v1.2.3 From c61ed70b00c93bdf42c7538a334f07e58c60bc4e Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Tue, 16 Mar 2010 11:43:04 -0700 Subject: Some more tweaks on <% %>. * The cache helper is now semantically "mark this region for caching" * As a result, <% x = cache do %> no longer works --- actionpack/lib/action_controller/caching/fragments.rb | 3 +-- actionpack/lib/action_view/helpers/cache_helper.rb | 3 ++- actionpack/lib/action_view/helpers/text_helper.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/caching/fragments.rb b/actionpack/lib/action_controller/caching/fragments.rb index 19bf3ddd3b..8a10bdfe23 100644 --- a/actionpack/lib/action_controller/caching/fragments.rb +++ b/actionpack/lib/action_controller/caching/fragments.rb @@ -44,9 +44,8 @@ module ActionController #:nodoc: buffer = view_context.output_buffer pos = buffer.length yield - fragment = buffer[pos..-1] + fragment = buffer.slice!(pos..-1) write_fragment(name, fragment, options) - fragment.is_a?(String) ? ActionView::NonConcattingString.new(fragment) : fragment end else ret = yield diff --git a/actionpack/lib/action_view/helpers/cache_helper.rb b/actionpack/lib/action_view/helpers/cache_helper.rb index 3729d7daa8..f5c2127d3f 100644 --- a/actionpack/lib/action_view/helpers/cache_helper.rb +++ b/actionpack/lib/action_view/helpers/cache_helper.rb @@ -32,7 +32,8 @@ module ActionView # Topics listed alphabetically # <% end %> def cache(name = {}, options = nil, &block) - controller.fragment_for(name, options, &block) + safe_concat controller.fragment_for(name, options, &block) + nil end end end diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index b19a9754f4..b5bf813e07 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -29,7 +29,7 @@ module ActionView end def safe_concat(string) - output_buffer.safe_concat(string) + output_buffer.respond_to?(:safe_concat) ? output_buffer.safe_concat(string) : concat(string) end # Truncates a given +text+ after a given :length if +text+ is longer than :length -- cgit v1.2.3 From 12bf636461e3aab661119ceb3a104cfb70a11666 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 16 Mar 2010 17:36:09 -0300 Subject: translation method of TranslationHelper module returns always SafeBuffer [#4194 status:resolved] Signed-off-by: Jeremy Kemper --- actionpack/lib/action_view/helpers/translation_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/translation_helper.rb b/actionpack/lib/action_view/helpers/translation_helper.rb index f996762d6f..26ba4e2ca4 100644 --- a/actionpack/lib/action_view/helpers/translation_helper.rb +++ b/actionpack/lib/action_view/helpers/translation_helper.rb @@ -13,7 +13,7 @@ module ActionView def translate(key, options = {}) options[:raise] = true translation = I18n.translate(scope_key_by_partial(key), options) - translation.respond_to?(:html_safe) ? translation.html_safe : translation + (translation.respond_to?(:join) ? translation.join : translation).html_safe rescue I18n::MissingTranslationData => e keys = I18n.normalize_keys(e.locale, e.key, e.options[:scope]) content_tag('span', keys.join(', '), :class => 'translation_missing') -- cgit v1.2.3 From 56fb60ebfe9a20ced1366f3e35b2f9bd0bac8e45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 16 Mar 2010 23:35:45 +0100 Subject: Fix rendering of HTML partials inside JS templates [#4197 status:resolved] --- actionpack/lib/action_view/render/layouts.rb | 17 ++++++++++++++--- actionpack/lib/action_view/template.rb | 2 ++ 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/render/layouts.rb b/actionpack/lib/action_view/render/layouts.rb index 0cb688ca77..b4720aa681 100644 --- a/actionpack/lib/action_view/render/layouts.rb +++ b/actionpack/lib/action_view/render/layouts.rb @@ -43,10 +43,16 @@ module ActionView # This is the method which actually finds the layout using details in the lookup # context object. If no layout is found, it checkes if at least a layout with # the given name exists across all details before raising the error. - def find_layout(layout) #:nodoc: + # + # If self.formats contains several formats, just the first one is considered in + # the layout lookup. + def find_layout(layout) begin - layout =~ /^\// ? - with_fallbacks { find_template(layout) } : find_template(layout) + if formats.size == 1 + _find_layout(layout) + else + update_details(:formats => self.formats[0,1]){ _find_layout(layout) } + end rescue ActionView::MissingTemplate => e update_details(:formats => nil) do raise unless template_exists?(layout) @@ -54,6 +60,11 @@ module ActionView end end + def _find_layout(layout) #:nodoc: + layout =~ /^\// ? + with_fallbacks { find_template(layout) } : find_template(layout) + end + # Contains the logic that actually renders the layout. def _render_layout(layout, locals, &block) #:nodoc: layout.render(self, locals){ |*name| _layout_for(*name, &block) } diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index b4fdb49d3b..15fafac53d 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -31,7 +31,9 @@ module ActionView format = details[:format] format ||= handler.default_format.to_sym if handler.respond_to?(:default_format) format ||= :html + @formats = [format.to_sym] + @formats << :html if @formats.first == :js end def render(view, locals, &block) -- cgit v1.2.3 From 3abf5ad7f8b23d955225ba96e82fd5565dd2571d Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Tue, 16 Mar 2010 12:38:37 -0700 Subject: Make RouteSet#finalize! a NOOP if it's been called already. Call finalize! the first time call() and url_for() are called if the RouteSet has not been finalized yet. --- actionpack/lib/action_dispatch/routing/route_set.rb | 5 +++++ 1 file changed, 5 insertions(+) (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 722be432c7..048764263e 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -219,6 +219,8 @@ module ActionDispatch end def finalize! + return if @finalized + @finalized = true @set.add_route(NotFound) install_helpers @set.freeze @@ -227,6 +229,7 @@ module ActionDispatch def clear! # Clear the controller cache so we may discover new ones @controller_constraints = nil + @finalized = false routes.clear named_routes.clear @set = ::Rack::Mount::RouteSet.new(:parameters_key => PARAMETERS_KEY) @@ -406,6 +409,7 @@ module ActionDispatch RESERVED_OPTIONS = [:anchor, :params, :only_path, :host, :protocol, :port, :trailing_slash] def url_for(options) + finalize! options = default_url_options.merge(options || {}) handle_positional_args(options) @@ -437,6 +441,7 @@ module ActionDispatch end def call(env) + finalize! @set.call(env) end -- cgit v1.2.3 From 23b6def0eb76ac0719e420fce91ba862f880a37b Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Tue, 16 Mar 2010 14:55:42 -0700 Subject: Do not always include the named URL helpers into AC::Base and AV::Base. --- actionpack/lib/action_dispatch/routing/route_set.rb | 1 - .../lib/action_dispatch/testing/assertions/routing.rb | 18 ++++++++++++++++-- actionpack/lib/action_view/base.rb | 4 ++++ actionpack/lib/action_view/helpers/url_helper.rb | 7 +++++++ actionpack/lib/action_view/test_case.rb | 3 ++- 5 files changed, 29 insertions(+), 4 deletions(-) (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 048764263e..5537bbbbe8 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -222,7 +222,6 @@ module ActionDispatch return if @finalized @finalized = true @set.add_route(NotFound) - install_helpers @set.freeze end diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index 1d7e8090e4..eb28cd5107 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -145,11 +145,25 @@ module ActionDispatch old_routes, @router = @router, ActionDispatch::Routing::RouteSet.new old_controller, @controller = @controller, @controller.clone if @controller _router = @router - @controller.singleton_class.send(:send, :include, @router.url_helpers) if @controller + + # Unfortunately, there is currently an abstraction leak between AC::Base + # and AV::Base which requires having the URL helpers in both AC and AV. + # To do this safely at runtime for tests, we need to bump up the helper serial + # to that the old AV subclass isn't cached. + # + # TODO: Make this unnecessary + if @controller + @controller.singleton_class.send(:include, @router.url_helpers) + @controller.class._helper_serial += 1 + @controller.view_context.singleton_class.send(:include, @router.url_helpers) + end yield @router ensure @router = old_routes - @controller = old_controller if @controller + if @controller + @controller = old_controller + @controller.class._helper_serial += 1 if @controller + end end # ROUTES TODO: These assertions should really work in an integration context diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index 3920d8593f..daabe6d196 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -235,6 +235,10 @@ module ActionView #:nodoc: include controller._helpers self.helpers = controller._helpers end + + if controller.respond_to?(:_router) + include controller._router.url_helpers + end end else klass = self diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 94f1cecade..f877378ebe 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -9,6 +9,9 @@ module ActionView # This allows you to use the same format for links in views # and controllers. module UrlHelper + extend ActiveSupport::Concern + + include ActionDispatch::Routing::UrlFor include JavaScriptHelper # Need to map default url options to controller one. @@ -16,6 +19,10 @@ module ActionView controller.send(:default_url_options, *args) end + def url_options + controller.url_options + end + # Returns the URL for the set of +options+ provided. This takes the # same options as +url_for+ in Action Controller (see the # documentation for ActionController::Base#url_for). Note that by default diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index 1578ac9479..7e609eb640 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -124,7 +124,8 @@ module ActionView def _view view = ActionView::Base.new(ActionController::Base.view_paths, _assigns, @controller) - view.class.send :include, _helpers + view.singleton_class.send :include, _helpers + view.singleton_class.send :include, @controller._router.url_helpers view.output_buffer = self.output_buffer view end -- cgit v1.2.3 From 0c1ac36ccb7d72f3d17d950d030442a7e83d0708 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 16 Mar 2010 20:12:04 -0300 Subject: scope_key_by_partial fix for Ruby 1.9 when there's virtual_path [#4202 state:resolved] Signed-off-by: Jeremy Kemper --- actionpack/lib/action_view/helpers/translation_helper.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/translation_helper.rb b/actionpack/lib/action_view/helpers/translation_helper.rb index 26ba4e2ca4..457944dbb6 100644 --- a/actionpack/lib/action_view/helpers/translation_helper.rb +++ b/actionpack/lib/action_view/helpers/translation_helper.rb @@ -29,9 +29,10 @@ module ActionView private def scope_key_by_partial(key) - if (key.respond_to?(:join) ? key.join : key.to_s).first == "." + strkey = key.respond_to?(:join) ? key.join : key.to_s + if strkey.first == "." if @_virtual_path - @_virtual_path.gsub(%r{/_?}, ".") + key.to_s + @_virtual_path.gsub(%r{/_?}, ".") + strkey else raise "Cannot use t(#{key.inspect}) shortcut because path is not available" end -- cgit v1.2.3 From 7c49b1adbbe1ffd42c8cd6fc0439d53895c861cf Mon Sep 17 00:00:00 2001 From: wycats Date: Tue, 16 Mar 2010 17:28:44 -0700 Subject: Make sure options[:anchor] is correct in shorthand cases --- actionpack/lib/action_dispatch/routing/mapper.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index f9b27a5a03..668abb5fdf 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -51,7 +51,9 @@ module ActionDispatch options.merge!(:to => to).delete(path) if path when using_match_shorthand?(args, options) path = args.first - options = { :to => path.gsub("/", "#"), :as => path.gsub("/", "_") } + options = { :to => path.gsub("/", "#"), + :as => path.gsub("/", "_") + }.merge(options || {}) else path = args.first end @@ -301,7 +303,6 @@ module ActionDispatch options = args.extract_options! options = (@scope[:options] || {}).merge(options) - options[:anchor] = true unless options.key?(:anchor) if @scope[:name_prefix] && !options[:as].blank? options[:as] = "#{@scope[:name_prefix]}_#{options[:as]}" @@ -563,6 +564,8 @@ module ActionDispatch def match(*args) options = args.extract_options! + options[:anchor] = true unless options.key?(:anchor) + if args.length > 1 args.each { |path| match(path, options) } return self -- cgit v1.2.3 From 55aac2c6969e4f5209ba786120f1d7b57c80b9a0 Mon Sep 17 00:00:00 2001 From: wycats Date: Tue, 16 Mar 2010 17:32:42 -0700 Subject: Fix missing require --- actionpack/lib/action_view/helpers/url_helper.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index f877378ebe..79232e297f 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -1,6 +1,7 @@ require 'action_view/helpers/javascript_helper' require 'active_support/core_ext/array/access' require 'active_support/core_ext/hash/keys' +require 'action_dispatch' module ActionView module Helpers #:nodoc: -- cgit v1.2.3 From d69e5616e821afc40efa5936c5ab6e087eb4e0c6 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 16 Mar 2010 22:06:16 -0500 Subject: link_to_function is here to stay --- .../lib/action_view/helpers/javascript_helper.rb | 87 ++++++++++++++++++++++ .../lib/action_view/helpers/prototype_helper.rb | 33 -------- 2 files changed, 87 insertions(+), 33 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index 8dab3094dd..0aa539031d 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -89,6 +89,93 @@ module ActionView def javascript_cdata_section(content) #:nodoc: "\n//#{cdata_section("\n#{content}\n//")}\n".html_safe end + + # Returns a button with the given +name+ text that'll trigger a JavaScript +function+ using the + # onclick handler. + # + # The first argument +name+ is used as the button's value or display text. + # + # The next arguments are optional and may include the javascript function definition and a hash of html_options. + # + # The +function+ argument can be omitted in favor of an +update_page+ + # block, which evaluates to a string when the template is rendered + # (instead of making an Ajax request first). + # + # The +html_options+ will accept a hash of html attributes for the link tag. Some examples are :class => "nav_button", :id => "articles_nav_button" + # + # Note: if you choose to specify the javascript function in a block, but would like to pass html_options, set the +function+ parameter to nil + # + # Examples: + # button_to_function "Greeting", "alert('Hello world!')" + # button_to_function "Delete", "if (confirm('Really?')) do_delete()" + # button_to_function "Details" do |page| + # page[:details].visual_effect :toggle_slide + # end + # button_to_function "Details", :class => "details_button" do |page| + # page[:details].visual_effect :toggle_slide + # end + def button_to_function(name, *args, &block) + html_options = args.extract_options!.symbolize_keys + + function = block_given? ? update_page(&block) : args[0] || '' + onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function};" + + tag(:input, html_options.merge(:type => 'button', :value => name, :onclick => onclick)) + end + + # Returns a link of the given +name+ that will trigger a JavaScript +function+ using the + # onclick handler and return false after the fact. + # + # The first argument +name+ is used as the link text. + # + # The next arguments are optional and may include the javascript function definition and a hash of html_options. + # + # The +function+ argument can be omitted in favor of an +update_page+ + # block, which evaluates to a string when the template is rendered + # (instead of making an Ajax request first). + # + # The +html_options+ will accept a hash of html attributes for the link tag. Some examples are :class => "nav_button", :id => "articles_nav_button" + # + # Note: if you choose to specify the javascript function in a block, but would like to pass html_options, set the +function+ parameter to nil + # + # + # Examples: + # link_to_function "Greeting", "alert('Hello world!')" + # Produces: + # Greeting + # + # link_to_function(image_tag("delete"), "if (confirm('Really?')) do_delete()") + # Produces: + # + # Delete + # + # + # link_to_function("Show me more", nil, :id => "more_link") do |page| + # page[:details].visual_effect :toggle_blind + # page[:more_link].replace_html "Show me less" + # end + # Produces: + # Show me more + # + def link_to_function(name, *args, &block) + html_options = args.extract_options!.symbolize_keys + + function = block_given? ? update_page(&block) : args[0] || '' + onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function}; return false;" + href = html_options[:href] || '#' + + content_tag(:a, name, html_options.merge(:href => href, :onclick => onclick)) + end end end end diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index e46ca53275..ad3bc8c79c 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -102,39 +102,6 @@ module ActionView :form, :with, :update, :script, :type ]).merge(CALLBACKS) end - # Returns a button with the given +name+ text that'll trigger a JavaScript +function+ using the - # onclick handler. - # - # The first argument +name+ is used as the button's value or display text. - # - # The next arguments are optional and may include the javascript function definition and a hash of html_options. - # - # The +function+ argument can be omitted in favor of an +update_page+ - # block, which evaluates to a string when the template is rendered - # (instead of making an Ajax request first). - # - # The +html_options+ will accept a hash of html attributes for the link tag. Some examples are :class => "nav_button", :id => "articles_nav_button" - # - # Note: if you choose to specify the javascript function in a block, but would like to pass html_options, set the +function+ parameter to nil - # - # Examples: - # button_to_function "Greeting", "alert('Hello world!')" - # button_to_function "Delete", "if (confirm('Really?')) do_delete()" - # button_to_function "Details" do |page| - # page[:details].visual_effect :toggle_slide - # end - # button_to_function "Details", :class => "details_button" do |page| - # page[:details].visual_effect :toggle_slide - # end - def button_to_function(name, *args, &block) - html_options = args.extract_options!.symbolize_keys - - function = block_given? ? update_page(&block) : args[0] || '' - onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function};" - - tag(:input, html_options.merge(:type => 'button', :value => name, :onclick => onclick)) - end - # Returns the JavaScript needed for a remote function. # Takes the same arguments as link_to_remote. # -- cgit v1.2.3 From c7388124153e1b1f85965998e5d1c20eed670da8 Mon Sep 17 00:00:00 2001 From: wycats Date: Tue, 16 Mar 2010 21:37:43 -0700 Subject: Another missing require --- actionpack/lib/action_dispatch/routing.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing.rb b/actionpack/lib/action_dispatch/routing.rb index 5bc3205c51..c6e942555f 100644 --- a/actionpack/lib/action_dispatch/routing.rb +++ b/actionpack/lib/action_dispatch/routing.rb @@ -1,5 +1,6 @@ require 'active_support/core_ext/object/to_param' require 'active_support/core_ext/regexp' +require 'action_controller/polymorphic_routes' module ActionDispatch # == Routing -- cgit v1.2.3 From cd9ffd11e13ef6e62eba2cbd5c3760ff04132820 Mon Sep 17 00:00:00 2001 From: wycats Date: Tue, 16 Mar 2010 23:24:00 -0700 Subject: Eliminate warnings for AM on 1.8 --- actionpack/lib/abstract_controller/layouts.rb | 4 ++++ actionpack/lib/action_controller/metal.rb | 6 +++++- actionpack/lib/action_controller/metal/rack_delegation.rb | 6 ++---- actionpack/lib/action_dispatch/http/filter_parameters.rb | 1 - actionpack/lib/action_view/helpers/capture_helper.rb | 2 +- 5 files changed, 12 insertions(+), 7 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb index 95a6101109..528a430b04 100644 --- a/actionpack/lib/abstract_controller/layouts.rb +++ b/actionpack/lib/abstract_controller/layouts.rb @@ -1,3 +1,5 @@ +require "active_support/core_ext/module/remove_method" + module AbstractController # Layouts reverse the common pattern of including shared headers and footers in many templates to isolate changes in # repeated setups. The inclusion pattern has pages that look like this: @@ -237,6 +239,8 @@ module AbstractController # name, return that string. Otherwise, use the superclass' # layout (which might also be implied) def _write_layout_method + remove_possible_method(:_layout) + case defined?(@_layout) ? @_layout : nil when String self.class_eval %{def _layout; #{@_layout.inspect} end} diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb index eebd2c943a..a148c19a31 100644 --- a/actionpack/lib/action_controller/metal.rb +++ b/actionpack/lib/action_controller/metal.rb @@ -34,7 +34,7 @@ module ActionController # and response object available. You might wish to control the # environment and response manually for performance reasons. - attr_internal :status, :headers, :content_type, :response, :request + attr_internal :headers, :response, :request delegate :session, :to => "@_request" def initialize(*) @@ -62,6 +62,10 @@ module ActionController headers["Location"] = url end + def status + @_status + end + def status=(status) @_status = Rack::Utils.status_code(status) end diff --git a/actionpack/lib/action_controller/metal/rack_delegation.rb b/actionpack/lib/action_controller/metal/rack_delegation.rb index 37106733cb..060117756e 100644 --- a/actionpack/lib/action_controller/metal/rack_delegation.rb +++ b/actionpack/lib/action_controller/metal/rack_delegation.rb @@ -5,10 +5,8 @@ module ActionController module RackDelegation extend ActiveSupport::Concern - included do - delegate :headers, :status=, :location=, :content_type=, - :status, :location, :content_type, :to => "@_response" - end + delegate :headers, :status=, :location=, :content_type=, + :status, :location, :content_type, :to => "@_response" def dispatch(action, request) @_response = ActionDispatch::Response.new diff --git a/actionpack/lib/action_dispatch/http/filter_parameters.rb b/actionpack/lib/action_dispatch/http/filter_parameters.rb index 451b79b190..e42b4d09b0 100644 --- a/actionpack/lib/action_dispatch/http/filter_parameters.rb +++ b/actionpack/lib/action_dispatch/http/filter_parameters.rb @@ -25,7 +25,6 @@ module ActionDispatch module FilterParameters extend ActiveSupport::Concern - mattr_reader :compiled_parameter_filter_for @@compiled_parameter_filter_for = {} # Return a hash of parameters with all sensitive data replaced. diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb index 42a67756e4..f0be814700 100644 --- a/actionpack/lib/action_view/helpers/capture_helper.rb +++ b/actionpack/lib/action_view/helpers/capture_helper.rb @@ -32,7 +32,7 @@ module ActionView # def capture(*args) value = nil - buffer = with_output_buffer { value = yield *args } + buffer = with_output_buffer { value = yield(*args) } if string = buffer.presence || value and string.is_a?(String) NonConcattingString.new(string) end -- cgit v1.2.3 From a5587efc1903fd27d4b179753aa6e139445ad18c Mon Sep 17 00:00:00 2001 From: wycats Date: Wed, 17 Mar 2010 00:15:55 -0700 Subject: Remove some 1.9 warnings (resulting in some fixed bugs). Remaining AM warnings are in dependencies. --- actionpack/lib/action_controller/metal/redirecting.rb | 2 +- actionpack/lib/action_view/base.rb | 1 + actionpack/lib/action_view/helpers/form_helper.rb | 6 +++--- actionpack/lib/action_view/helpers/javascript_helper.rb | 1 - actionpack/lib/action_view/helpers/prototype_helper.rb | 2 -- actionpack/lib/action_view/helpers/text_helper.rb | 2 +- actionpack/lib/action_view/template.rb | 1 - 7 files changed, 6 insertions(+), 9 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/metal/redirecting.rb b/actionpack/lib/action_controller/metal/redirecting.rb index 25e4e18493..b5f1d23ef0 100644 --- a/actionpack/lib/action_controller/metal/redirecting.rb +++ b/actionpack/lib/action_controller/metal/redirecting.rb @@ -76,7 +76,7 @@ module ActionController # The scheme name consist of a letter followed by any combination of # letters, digits, and the plus ("+"), period ("."), or hyphen ("-") # characters; and is terminated by a colon (":"). - when %r{^\w[\w\d+.-]*:.*} + when %r{^\w[\w+.-]*:.*} options when String request.protocol + request.host_with_port + options diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index daabe6d196..326b79f9bf 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -187,6 +187,7 @@ module ActionView #:nodoc: @@debug_rjs = false class_attribute :helpers + remove_method :helpers attr_reader :helpers class << self diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 48df26efaa..01a585af95 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1014,7 +1014,7 @@ module ActionView class FormBuilder #:nodoc: # The methods which wrap a form helper call. class_inheritable_accessor :field_helpers - self.field_helpers = (FormHelper.instance_methods - ['form_for']) + self.field_helpers = (FormHelper.instance_method_names - ['form_for']) attr_accessor :object_name, :object, :options @@ -1040,7 +1040,7 @@ module ActionView end (field_helpers - %w(label check_box radio_button fields_for hidden_field)).each do |selector| - src = <<-end_src + src, file, line = <<-end_src, __FILE__, __LINE__ + 1 def #{selector}(method, options = {}) # def text_field(method, options = {}) @template.send( # @template.send( #{selector.inspect}, # "text_field", @@ -1049,7 +1049,7 @@ module ActionView objectify_options(options)) # objectify_options(options)) end # end end_src - class_eval src, __FILE__, __LINE__ + class_eval src, file, line end def fields_for(record_or_name_or_array, *args, &block) diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index 0aa539031d..5635f88c11 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -1,5 +1,4 @@ require 'action_view/helpers/tag_helper' -require 'action_view/helpers/prototype_helper' module ActionView module Helpers diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index ad3bc8c79c..2e5fe5744e 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -853,5 +853,3 @@ module ActionView end end end - -require 'action_view/helpers/javascript_helper' diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index b5bf813e07..13fad0ed7a 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -576,7 +576,7 @@ module ActionView # each email is yielded and the result is used as the link text. def auto_link_email_addresses(text, html_options = {}) body = text.dup - text.gsub(/([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/) do + text.gsub(/([\w\.!#\$%\-+]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/) do text = $1 if body.match(/]*>(.*)(#{Regexp.escape(text)})(.*)<\/a>/) diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index 15fafac53d..6315e502dd 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -2,7 +2,6 @@ # This is so that templates compiled in this file are UTF-8 require 'set' -require "action_view/template/resolver" module ActionView class Template -- cgit v1.2.3 From 13a783672aad338b9c7ade5319ec7967768905d7 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 17 Mar 2010 16:04:41 -0500 Subject: Install url helpers on module instance so they can be accessed globally --- actionpack/lib/action_dispatch/routing/route_set.rb | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (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 5537bbbbe8..8936d7659a 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -65,7 +65,7 @@ module ActionDispatch # named routes. class NamedRouteCollection #:nodoc: include Enumerable - attr_reader :routes, :helpers + attr_reader :routes, :helpers, :module def initialize clear! @@ -241,21 +241,29 @@ module ActionDispatch def url_helpers @url_helpers ||= begin - router = self + routes = self - Module.new do + helpers = Module.new do extend ActiveSupport::Concern include UrlFor + @routes = routes + class << self + delegate :url_for, :to => '@routes' + end + extend routes.named_routes.module + # ROUTES TODO: install_helpers isn't great... can we make a module with the stuff that # we can include? # Yes plz - JP included do - router.install_helpers(self) + routes.install_helpers(self) end - define_method(:_router) { router } + define_method(:_router) { routes } end + + helpers end end -- cgit v1.2.3 From 947f86c699b33bd44703b3554db58e4cfca37c86 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Wed, 17 Mar 2010 14:19:42 -0700 Subject: Modify assert_template to use instrumentation --- actionpack/lib/action_controller/test_case.rb | 82 ++++++++++++++++++++++ .../action_dispatch/testing/assertions/response.rb | 52 -------------- actionpack/lib/action_view/template.rb | 8 ++- actionpack/lib/action_view/test_case.rb | 1 + 4 files changed, 89 insertions(+), 54 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index cdb5db32aa..107f70d3a3 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -2,6 +2,87 @@ require 'rack/session/abstract/id' require 'action_view/test_case' module ActionController + module TemplateAssertions + extend ActiveSupport::Concern + + included do + setup :setup_subscriptions + teardown :teardown_subscriptions + end + + def setup_subscriptions + @partials = Hash.new(0) + @templates = Hash.new(0) + ActiveSupport::Notifications.subscribe("action_view.slow_render_template") do |name, start, finish, id, payload| + path = payload[:virtual_path] + next unless path + partial = path =~ /^.*\/_[^\/]*$/ + if partial + @partials[path] += 1 + @partials[path.split("/").last] += 1 + @templates[path] += 1 + else + @templates[path] += 1 + end + end + end + + def teardown_subscriptions + ActiveSupport::Notifications.unsubscribe("action_view.slow_render_template") + end + + # Asserts that the request was rendered with the appropriate template file or partials + # + # ==== Examples + # + # # assert that the "new" view template was rendered + # assert_template "new" + # + # # assert that the "_customer" partial was rendered twice + # assert_template :partial => '_customer', :count => 2 + # + # # assert that no partials were rendered + # assert_template :partial => false + # + def assert_template(options = {}, message = nil) + validate_request! + + case options + when NilClass, String + rendered = @templates + msg = build_message(message, + "expecting but rendering with ", + options, rendered.keys.join(', ')) + assert_block(msg) do + if options.nil? + @templates.blank? + else + rendered.any? { |t,num| t.match(options) } + end + end + when Hash + if expected_partial = options[:partial] + if expected_count = options[:count] + actual_count = @partials[expected_partial] + # actual_count = found.nil? ? 0 : found[1] + msg = build_message(message, + "expecting ? to be rendered ? time(s) but rendered ? time(s)", + expected_partial, expected_count, actual_count) + assert(actual_count == expected_count.to_i, msg) + else + msg = build_message(message, + "expecting partial but action rendered ", + options[:partial], @partials.keys) + assert(@partials.include?(expected_partial), msg) + end + else + assert @partials.empty?, + "Expected no partials to be rendered" + end + end + end + end + class TestRequest < ActionDispatch::TestRequest #:nodoc: def initialize(env = {}) super @@ -181,6 +262,7 @@ module ActionController # assert_redirected_to page_url(:title => 'foo') class TestCase < ActiveSupport::TestCase include ActionDispatch::TestProcess + include ActionController::TemplateAssertions # Executes a request simulating GET HTTP method and set/volley the response def get(action, parameters = nil, session = nil, flash = nil) diff --git a/actionpack/lib/action_dispatch/testing/assertions/response.rb b/actionpack/lib/action_dispatch/testing/assertions/response.rb index 937c9f48d2..ec5e9efe44 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/response.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/response.rb @@ -73,58 +73,6 @@ module ActionDispatch end end - # Asserts that the request was rendered with the appropriate template file or partials - # - # ==== Examples - # - # # assert that the "new" view template was rendered - # assert_template "new" - # - # # assert that the "_customer" partial was rendered twice - # assert_template :partial => '_customer', :count => 2 - # - # # assert that no partials were rendered - # assert_template :partial => false - # - def assert_template(options = {}, message = nil) - validate_request! - - case options - when NilClass, String - rendered = (@controller.template.rendered[:template] || []).map { |t| t.identifier } - msg = build_message(message, - "expecting but rendering with ", - options, rendered.join(', ')) - assert_block(msg) do - if options.nil? - @controller.template.rendered[:template].blank? - else - rendered.any? { |t| t.match(options) } - end - end - when Hash - if expected_partial = options[:partial] - partials = @controller.template.rendered[:partials] - if expected_count = options[:count] - found = partials.detect { |p, _| p.identifier.match(expected_partial) } - actual_count = found.nil? ? 0 : found.second - msg = build_message(message, - "expecting ? to be rendered ? time(s) but rendered ? time(s)", - expected_partial, expected_count, actual_count) - assert(actual_count == expected_count.to_i, msg) - else - msg = build_message(message, - "expecting partial but action rendered ", - options[:partial], partials.keys) - assert(partials.keys.any? { |p| p.identifier.match(expected_partial) }, msg) - end - else - assert @controller.template.rendered[:partials].empty?, - "Expected no partials to be rendered" - end - end - end - private # Proxy to to_param if the object will respond to it. def parameterize(value) diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index 6315e502dd..ad37eb4c4a 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -36,8 +36,12 @@ module ActionView end def render(view, locals, &block) - method_name = compile(locals, view) - view.send(method_name, locals, &block) + # TODO: Revisit this name + # This is only slow if it's being listened to. Do not instrument this in production. + ActiveSupport::Notifications.instrument("action_view.slow_render_template", :virtual_path => @virtual_path) do + method_name = compile(locals, view) + view.send(method_name, locals, &block) + end rescue Exception => e if e.is_a?(Template::Error) e.sub_template_of(self) diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index 7e609eb640..8750a501b7 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -42,6 +42,7 @@ module ActionView end include ActionDispatch::Assertions, ActionDispatch::TestProcess + include ActionController::TemplateAssertions include ActionView::Context include ActionController::PolymorphicRoutes -- cgit v1.2.3 From 6416a35f4b3290a93145d40045147fc01d36e756 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Wed, 17 Mar 2010 14:23:00 -0700 Subject: Remove unneeded AV::Base and AV::Template monkey-patches --- actionpack/lib/abstract_controller/rendering.rb | 1 + actionpack/lib/action_view/test_case.rb | 21 --------------------- 2 files changed, 1 insertion(+), 21 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 16664098e5..94c9ec7478 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -1,4 +1,5 @@ require "abstract_controller/base" +require "action_view/base" module AbstractController class DoubleRenderError < Error diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index 8750a501b7..1c69c23bfc 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -2,27 +2,6 @@ require 'action_controller/test_case' require 'action_view' module ActionView - class Base - alias_method :initialize_without_template_tracking, :initialize - def initialize(*args) - @_rendered = { :template => nil, :partials => Hash.new(0) } - initialize_without_template_tracking(*args) - end - - attr_internal :rendered - end - - class Template - alias_method :render_without_tracking, :render - def render(view, locals, &blk) - rendered = view.rendered - rendered[:partials][self] += 1 if partial? - rendered[:template] ||= [] - rendered[:template] << self - render_without_tracking(view, locals, &blk) - end - end - class TestCase < ActiveSupport::TestCase class TestController < ActionController::Base attr_accessor :request, :response, :params -- cgit v1.2.3 From 21dcbb17de86b92df1a67e233fdc457be4fdf2d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 17 Mar 2010 23:09:28 +0100 Subject: Ensure json is loaded before using responders. --- actionpack/lib/abstract_controller/rendering.rb | 1 - actionpack/lib/action_controller/metal/responder.rb | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 94c9ec7478..16664098e5 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -1,5 +1,4 @@ require "abstract_controller/base" -require "action_view/base" module AbstractController class DoubleRenderError < Error diff --git a/actionpack/lib/action_controller/metal/responder.rb b/actionpack/lib/action_controller/metal/responder.rb index 6178a59029..0b2cee6868 100644 --- a/actionpack/lib/action_controller/metal/responder.rb +++ b/actionpack/lib/action_controller/metal/responder.rb @@ -1,3 +1,5 @@ +require 'active_support/json' + module ActionController #:nodoc: # Responder is responsible for exposing a resource to different mime requests, # usually depending on the HTTP verb. The responder is triggered when -- cgit v1.2.3 From a6dc227167a8a720bd18495268305b15aa08d8f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 17 Mar 2010 23:44:03 +0100 Subject: Mark bang instrumentations as something that you shuold not be listening to. --- actionpack/lib/action_controller/test_case.rb | 4 ++-- actionpack/lib/action_view/template.rb | 11 +++-------- 2 files changed, 5 insertions(+), 10 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 107f70d3a3..330b950d7c 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -13,7 +13,7 @@ module ActionController def setup_subscriptions @partials = Hash.new(0) @templates = Hash.new(0) - ActiveSupport::Notifications.subscribe("action_view.slow_render_template") do |name, start, finish, id, payload| + ActiveSupport::Notifications.subscribe("action_view.render_template!") do |name, start, finish, id, payload| path = payload[:virtual_path] next unless path partial = path =~ /^.*\/_[^\/]*$/ @@ -28,7 +28,7 @@ module ActionController end def teardown_subscriptions - ActiveSupport::Notifications.unsubscribe("action_view.slow_render_template") + ActiveSupport::Notifications.unsubscribe("action_view.render_template!") end # Asserts that the request was rendered with the appropriate template file or partials diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index ad37eb4c4a..9145d007a8 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -23,7 +23,6 @@ module ActionView @identifier = identifier @handler = handler - @partial = details[:partial] @virtual_path = details[:virtual_path] @method_names = {} @@ -36,9 +35,9 @@ module ActionView end def render(view, locals, &block) - # TODO: Revisit this name - # This is only slow if it's being listened to. Do not instrument this in production. - ActiveSupport::Notifications.instrument("action_view.slow_render_template", :virtual_path => @virtual_path) do + # Notice that we use a bang in this instrumentation because you don't want to + # consume this in production. This is only slow if it's being listened to. + ActiveSupport::Notifications.instrument("action_view.render_template!", :virtual_path => @virtual_path) do method_name = compile(locals, view) view.send(method_name, locals, &block) end @@ -63,10 +62,6 @@ module ActionView @counter_name ||= "#{variable_name}_counter".to_sym end - def partial? - @partial - end - def inspect if defined?(Rails.root) identifier.sub("#{Rails.root}/", '') -- cgit v1.2.3 From d9375f3f302a5d1856ad57946c7263d4e6a45a2a Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Wed, 17 Mar 2010 16:28:05 -0700 Subject: Modify assert_template to use notifications. Also, remove ActionController::Base#template since it is no longer needed. --- .../lib/action_controller/metal/compatibility.rb | 9 --------- actionpack/lib/action_controller/test_case.rb | 20 ++++++++++++++++++++ actionpack/lib/action_view/base.rb | 9 +++++++-- .../lib/action_view/helpers/prototype_helper.rb | 2 +- actionpack/lib/action_view/render/rendering.rb | 3 +-- actionpack/lib/action_view/test_case.rb | 4 +++- 6 files changed, 32 insertions(+), 15 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/metal/compatibility.rb b/actionpack/lib/action_controller/metal/compatibility.rb index ab8d87b2c4..e6cea483bb 100644 --- a/actionpack/lib/action_controller/metal/compatibility.rb +++ b/actionpack/lib/action_controller/metal/compatibility.rb @@ -40,15 +40,6 @@ module ActionController def initialize_template_class(*) end def assign_shortcuts(*) end - def template - @template ||= view_context - end - - def process_action(*) - template - super - end - def _normalize_options(options) if options[:action] && options[:action].to_s.include?(?/) ActiveSupport::Deprecation.warn "Giving a path to render :action is deprecated. " << diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 330b950d7c..8ab0c32a9e 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -13,6 +13,13 @@ module ActionController def setup_subscriptions @partials = Hash.new(0) @templates = Hash.new(0) + @layouts = Hash.new(0) + + ActiveSupport::Notifications.subscribe("action_view.render_template") do |name, start, finish, id, payload| + path = payload[:layout] + @layouts[path] += 1 + end + ActiveSupport::Notifications.subscribe("action_view.render_template!") do |name, start, finish, id, payload| path = payload[:virtual_path] next unless path @@ -69,6 +76,19 @@ module ActionController "expecting ? to be rendered ? time(s) but rendered ? time(s)", expected_partial, expected_count, actual_count) assert(actual_count == expected_count.to_i, msg) + elsif options.key?(:layout) + msg = build_message(message, + "expecting layout but action rendered ", + expected_layout, @layouts.keys) + + case layout = options[:layout] + when String + assert(@layouts.include?(expected_layout), msg) + when Regexp + assert(@layouts.any? {|l| l =~ layout }, msg) + when nil + assert(@layouts.empty?, msg) + end else msg = build_message(message, "expecting partial but action rendered ", diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index 326b79f9bf..4d9f53cf95 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -196,7 +196,7 @@ module ActionView #:nodoc: end attr_accessor :base_path, :assigns, :template_extension, :lookup_context - attr_internal :captures, :request, :layout, :controller, :template, :config + attr_internal :captures, :request, :controller, :template, :config delegate :find_template, :template_exists?, :formats, :formats=, :locale, :locale=, :view_paths, :view_paths=, :with_fallbacks, :update_details, :to => :lookup_context @@ -206,6 +206,11 @@ module ActionView #:nodoc: delegate :logger, :to => :controller, :allow_nil => true + # TODO: HACK FOR RJS + def view_context + self + end + def self.xss_safe? #:nodoc: true end @@ -254,7 +259,7 @@ module ActionView #:nodoc: @helpers = self.class.helpers || Module.new @_controller = controller - @_config = ActiveSupport::InheritableOptions.new(controller.config) if controller + @_config = ActiveSupport::InheritableOptions.new(controller.config) if controller && controller.respond_to?(:config) @_content_for = Hash.new { |h,k| h[k] = ActiveSupport::SafeBuffer.new } @_virtual_path = nil diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index 2e5fe5744e..aba2565c67 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -582,7 +582,7 @@ module ActionView # page.hide 'spinner' # end def update_page(&block) - JavaScriptGenerator.new(@template, &block).to_s.html_safe + JavaScriptGenerator.new(view_context, &block).to_s.html_safe end # Works like update_page but wraps the generated JavaScript in a