From 3859828d89d378986af0fc2390608b00aad5e912 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 31 Mar 2010 19:49:29 -0700 Subject: HTML safety: give a deprecation warning if an array of option tags is passed to select tag. Be sure to join the tag yourself and mark them .html_safe --- actionpack/lib/action_view/helpers/form_tag_helper.rb | 4 ++++ 1 file changed, 4 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 ca100e102e..0d47c6eecb 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -93,6 +93,10 @@ module ActionView # # => def select_tag(name, option_tags = nil, options = {}) + if Array === option_tags + ActiveSupport::Deprecation.warn 'Passing an array of option_tags to select_tag implicitly joins them without marking them as HTML-safe. Pass option_tags.join.html_safe instead.', caller + end + html_name = (options[:multiple] == true && !name.to_s.ends_with?("[]")) ? "#{name}[]" : name if blank = options.delete(:include_blank) if blank.kind_of?(String) -- cgit v1.2.3 From 81e69332466003732846bd7dbc04e8550bfe16a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernardo=20de=20P=C3=A1dua?= Date: Thu, 1 Apr 2010 01:19:09 -0300 Subject: Fix error in number_with_precision with :significant option and zero value [#4306 state: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/number_helper.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb index 605e5d5873..01fecc0f23 100644 --- a/actionpack/lib/action_view/helpers/number_helper.rb +++ b/actionpack/lib/action_view/helpers/number_helper.rb @@ -273,8 +273,12 @@ module ActionView strip_insignificant_zeros = options.delete :strip_insignificant_zeros if significant and precision > 0 - digits = (Math.log10(number) + 1).floor - rounded_number = BigDecimal.new((number / 10 ** (digits - precision)).to_s).round.to_f * 10 ** (digits - precision) + if number == 0 + digits, rounded_number = 1, 0 + else + digits = (Math.log10(number) + 1).floor + rounded_number = BigDecimal.new((number / 10 ** (digits - precision)).to_s).round.to_f * 10 ** (digits - precision) + end precision = precision - digits precision = precision > 0 ? precision : 0 #don't let it be negative else -- cgit v1.2.3 From d868cb4f8a84b6275b6407b20bb3ba939a53681a Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 1 Apr 2010 13:36:45 -0700 Subject: Prep for beta2, depend on latest Bundler --- actionpack/lib/action_pack/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_pack/version.rb b/actionpack/lib/action_pack/version.rb index 72a1cd30ad..0b40465a79 100644 --- a/actionpack/lib/action_pack/version.rb +++ b/actionpack/lib/action_pack/version.rb @@ -3,7 +3,7 @@ module ActionPack MAJOR = 3 MINOR = 0 TINY = 0 - BUILD = "beta1" + BUILD = "beta2" STRING = [MAJOR, MINOR, TINY, BUILD].join('.') end -- cgit v1.2.3 From dc5300adb6d46252c26e239ac67e3ca6e5e2d77b Mon Sep 17 00:00:00 2001 From: Paul Sadauskas Date: Mon, 8 Feb 2010 11:08:31 -0700 Subject: Slightly less annoying check for acceptable mime_types. This allows Accept: application/json, application/jsonp (and the like), but still blacklists browsers. Essentially, we use normal content negotiation unless you include */* in your list, in which case we assume you're a browser and send HTML [#3541 state:resolved] --- actionpack/lib/action_dispatch/http/mime_negotiation.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/http/mime_negotiation.rb b/actionpack/lib/action_dispatch/http/mime_negotiation.rb index be89924015..4082770b85 100644 --- a/actionpack/lib/action_dispatch/http/mime_negotiation.rb +++ b/actionpack/lib/action_dispatch/http/mime_negotiation.rb @@ -48,7 +48,7 @@ module ActionDispatch @env["action_dispatch.request.formats"] ||= if parameters[:format] Array(Mime[parameters[:format]]) - elsif xhr? || (accept && !accept.include?(?,)) + elsif xhr? || (accept && accept !~ /,\s*\*\/\*/) accepts else [Mime::HTML] @@ -87,4 +87,4 @@ module ActionDispatch end end end -end \ No newline at end of file +end -- cgit v1.2.3 From a0cdb0499eecd40ba18d33226767783e4a058847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 2 Apr 2010 19:13:47 +0200 Subject: Maintain the usage of :as consistent in the router. Whenever it's supplied, it changes the NAMED ROUTE. If you want to change the PATH, use :path instead. Example: resources :projects, :path => 'projetos' --- actionpack/lib/action_dispatch/routing/mapper.rb | 53 +++++++++++++----------- 1 file changed, 28 insertions(+), 25 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 8a84afd315..4e9112bc04 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -194,6 +194,21 @@ module ActionDispatch self end + def mount(app, options = nil) + if options + path = options.delete(:at) + else + options = app + app, path = options.find { |k, v| k.respond_to?(:call) } + options.delete(app) if app + end + + raise "A rack application must be specified" unless path + + match(path, options.merge(:to => app, :anchor => false)) + self + end + def default_url_options=(options) @set.default_url_options = options end @@ -380,14 +395,13 @@ module ActionDispatch [:index, :create, :new, :show, :update, :destroy, :edit] end - attr_reader :plural, :singular, :options + attr_reader :controller, :path, :options def initialize(entities, options = {}) - @name = entities.to_s - @options = options - - @plural = @name.pluralize - @singular = @name.singularize + @name = entities.to_s + @path = options.delete(:path) || @name + @controller = options.delete(:controller) || @name.to_s.pluralize + @options = options end def default_actions @@ -417,8 +431,12 @@ module ActionDispatch options[:as] || @name end - def controller - options[:controller] || plural + def plural + name.to_s.pluralize + end + + def singular + name.to_s.singularize end def member_name @@ -509,7 +527,7 @@ module ActionDispatch resource = SingletonResource.new(resources.pop, options) - scope(:path => resource.name.to_s, :controller => resource.controller) do + scope(:path => resource.path, :controller => resource.controller) do with_scope_level(:resource, resource) do scope(:name_prefix => resource.name.to_s, :as => "") do @@ -539,7 +557,7 @@ module ActionDispatch resource = Resource.new(resources.pop, options) - scope(:path => resource.name.to_s, :controller => resource.controller) do + scope(:path => resource.path, :controller => resource.controller) do with_scope_level(:resources, resource) do yield if block_given? @@ -603,21 +621,6 @@ module ActionDispatch end end - def mount(app, options = nil) - if options - path = options.delete(:at) - else - options = app - app, path = options.find { |k, v| k.respond_to?(:call) } - options.delete(app) if app - end - - raise "A rack application must be specified" unless path - - match(path, options.merge(:to => app, :anchor => false)) - self - end - def match(*args) options = args.extract_options! -- cgit v1.2.3 From d898a4ba425a201827f07a5bb11c8c6bf85159b8 Mon Sep 17 00:00:00 2001 From: Rolf Bjaanes Date: Fri, 2 Apr 2010 20:00:29 +0200 Subject: Raise exceptions instead of rendering error templates in test environment [#4315 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- actionpack/lib/action_dispatch/railtie.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/railtie.rb b/actionpack/lib/action_dispatch/railtie.rb index 563df0f256..7ea9182e9c 100644 --- a/actionpack/lib/action_dispatch/railtie.rb +++ b/actionpack/lib/action_dispatch/railtie.rb @@ -6,7 +6,8 @@ module ActionDispatch config.action_dispatch = ActiveSupport::OrderedOptions.new config.action_dispatch.x_sendfile_header = "" config.action_dispatch.ip_spoofing_check = true - + config.action_dispatch.show_exceptions = true + # Prepare dispatcher callbacks and run 'prepare' callbacks initializer "action_dispatch.prepare_dispatcher" do |app| # TODO: This used to say unless defined?(Dispatcher). Find out why and fix. -- cgit v1.2.3 From 997e22c2751c66f8bba31dcdf4d1054072156036 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 2 Apr 2010 20:54:10 +0200 Subject: Add a test which ensures action_dispatch.show_exceptions is properly disabled. --- actionpack/lib/action_dispatch/railtie.rb | 2 +- actionpack/lib/action_dispatch/testing/integration.rb | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/railtie.rb b/actionpack/lib/action_dispatch/railtie.rb index 7ea9182e9c..004c254e55 100644 --- a/actionpack/lib/action_dispatch/railtie.rb +++ b/actionpack/lib/action_dispatch/railtie.rb @@ -7,7 +7,7 @@ module ActionDispatch config.action_dispatch.x_sendfile_header = "" config.action_dispatch.ip_spoofing_check = true config.action_dispatch.show_exceptions = true - + # Prepare dispatcher callbacks and run 'prepare' callbacks initializer "action_dispatch.prepare_dispatcher" do |app| # TODO: This used to say unless defined?(Dispatcher). Find out why and fix. diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 621d63c5e2..031fa1dfb4 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -263,9 +263,7 @@ module ActionDispatch "HTTP_HOST" => host, "REMOTE_ADDR" => remote_addr, "CONTENT_TYPE" => "application/x-www-form-urlencoded", - "HTTP_ACCEPT" => accept, - - "action_dispatch.show_exceptions" => false + "HTTP_ACCEPT" => accept } (rack_environment || {}).each do |key, value| -- cgit v1.2.3 From ee7605ecf0d36d16cddd885bb9df6ebddda8ff39 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 2 Apr 2010 15:54:38 -0700 Subject: Key partial name cache on controller and object class *names* to avoid memory leaks in dev mode --- actionpack/lib/action_view/render/partials.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/render/partials.rb b/actionpack/lib/action_view/render/partials.rb index f04a89c1ac..4d23d55687 100644 --- a/actionpack/lib/action_view/render/partials.rb +++ b/actionpack/lib/action_view/render/partials.rb @@ -179,7 +179,7 @@ module ActionView def initialize(view_context, options, block) @view = view_context - @partial_names = PARTIAL_NAMES[@view.controller.class] + @partial_names = PARTIAL_NAMES[@view.controller.class.name] setup(options, block) end @@ -300,7 +300,7 @@ module ActionView end def partial_path(object = @object) - @partial_names[object.class] ||= begin + @partial_names[object.class.name] ||= begin object = object.to_model if object.respond_to?(:to_model) object.class.model_name.partial_path.dup.tap do |partial| -- cgit v1.2.3 From b29e89368841869c92d706addddd09f436a3ea2f Mon Sep 17 00:00:00 2001 From: wycats Date: Fri, 2 Apr 2010 19:21:19 -0700 Subject: Fix memory leak in dev mode --- actionpack/lib/action_view/template.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index 8abc1633ff..3df2bd8eed 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -18,6 +18,14 @@ module ActionView attr_reader :source, :identifier, :handler, :virtual_path, :formats + def self.finalizer_for(method_name) + proc do + ActionView::CompiledTemplates.module_eval do + remove_possible_method method_name + end + end + end + def initialize(source, identifier, handler, details) @source = source @identifier = identifier @@ -98,6 +106,7 @@ module ActionView begin ActionView::CompiledTemplates.module_eval(source, identifier, line) + ObjectSpace.define_finalizer(self, self.class.finalizer_for(method_name)) method_name rescue Exception => e # errors from template code if logger = (view && view.logger) -- cgit v1.2.3 From 3eb97531b8650db5cc7b9558cc3828c56a526b6a Mon Sep 17 00:00:00 2001 From: wycats Date: Sat, 3 Apr 2010 02:30:06 -0700 Subject: Refactored url_for in AV to have its own instances of the helpers instead of proxying back to the controller. This potentially allows for more standalone usage of AV. It also kicked up a lot of dust in the tests, which were mocking out controllers to get this behavior. By moving it to the view, it made a lot of the tests more standalone (a win) --- actionpack/lib/action_view/base.rb | 7 ++- actionpack/lib/action_view/helpers.rb | 9 ++-- actionpack/lib/action_view/helpers/form_helper.rb | 1 + actionpack/lib/action_view/helpers/url_helper.rb | 52 ++++++++++++++++------- actionpack/lib/action_view/test_case.rb | 7 ++- 5 files changed, 53 insertions(+), 23 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index a9b0715b2e..fde61e9df9 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -168,6 +168,8 @@ module ActionView #:nodoc: remove_method :helpers attr_reader :helpers + class_attribute :_router + class << self delegate :erb_trim_mode=, :to => 'ActionView::Template::Handlers::ERB' delegate :logger, :to => 'ActionController::Base', :allow_nil => true @@ -204,7 +206,10 @@ module ActionView #:nodoc: @assigns = assigns_for_first_render.each { |key, value| instance_variable_set("@#{key}", value) } @helpers = self.class.helpers || Module.new - @_controller = controller + if @_controller = controller + @_request = controller.request if controller.respond_to?(:request) + end + @_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.rb b/actionpack/lib/action_view/helpers.rb index a50c180f63..ba3bdd0d18 100644 --- a/actionpack/lib/action_view/helpers.rb +++ b/actionpack/lib/action_view/helpers.rb @@ -29,16 +29,13 @@ module ActionView #:nodoc: autoload :TranslationHelper autoload :UrlHelper - def self.included(base) - base.extend(ClassMethods) - end + extend ActiveSupport::Concern - module ClassMethods - include SanitizeHelper::ClassMethods + included do + extend SanitizeHelper::ClassMethods end include ActiveSupport::Benchmarkable - include ActiveModelHelper include AssetTagHelper include AtomFeedHelper diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 89560d0b49..6a14f0be9c 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -96,6 +96,7 @@ module ActionView extend ActiveSupport::Concern include FormTagHelper + include UrlHelper # Creates a form and a scope around a specific model object that is used # as a base for questioning about values for the fields. diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index b23d5fcb68..1415966869 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -13,14 +13,15 @@ module ActionView extend ActiveSupport::Concern include ActionDispatch::Routing::UrlFor - include JavaScriptHelper + include TagHelper # Need to map default url options to controller one. - def default_url_options(*args) #:nodoc: - controller.send(:default_url_options, *args) - end - + # def default_url_options(*args) #:nodoc: + # controller.send(:default_url_options, *args) + # end + # def url_options + return super unless controller.respond_to?(:url_options) controller.url_options end @@ -97,7 +98,7 @@ module ActionView when Hash options = { :only_path => options[:host].nil? }.update(options.symbolize_keys) escape = options.key?(:escape) ? options.delete(:escape) : false - controller.send(:url_for, options) + super when :back escape = false controller.request.env["HTTP_REFERER"] || 'javascript:history.back()' @@ -119,13 +120,24 @@ module ActionView # # ==== Signatures # - # link_to(name, options = {}, html_options = nil) - # link_to(options = {}, html_options = nil) do + # link_to(body, url, html_options = {}) + # # url is a String; you can use URL helpers like + # # posts_path + # + # link_to(body, url_options = {}, html_options = {}) + # # url_options, except :confirm or :method, + # # is passed to url_for + # + # link_to(options = {}, html_options = {}) do + # # name + # end + # + # link_to(url, html_options = {}) do # # name # end # # ==== Options - # * :confirm => 'question?' - This will allow the unobtrusive JavaScript + # * :confirm => 'question?' - This will allow the unobtrusive JavaScript # driver to prompt with the question specified. If the user accepts, the link is # processed normally, otherwise no action is taken. # * :method => symbol of HTTP verb - This modifier will dynamically @@ -138,7 +150,11 @@ module ActionView # 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. + # * :remote => true - This will allow the unobtrusive JavaScript + # driver to make an Ajax request to the URL in question instead of following + # the link. The drivers each provide mechanisms for listening for the + # completion of the Ajax request and performing JavaScript operations once + # they're complete # # ==== Examples # Because it relies on +url_for+, +link_to+ supports both older-style controller/action/id arguments @@ -220,8 +236,8 @@ module ActionView options = args[1] || {} html_options = args[2] - url = url_for(options) html_options = convert_options_to_data_attributes(options, html_options) + url = url_for(options) if html_options html_options = html_options.stringify_keys @@ -259,10 +275,10 @@ module ActionView # 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 use the unobtrusive JavaScript driver to + # * :confirm - This will use the unobtrusive JavaScript driver to # prompt with the question specified. If the user accepts, the link is # processed normally, otherwise no action is taken. - # * :remote - If set to true, will allow the Unobtrusive JavaScript drivers to control the + # * :remote - If set to true, will allow the Unobtrusive JavaScript drivers to control the # submit behaviour. By default this behaviour is an ajax submit. # # ==== Examples @@ -282,7 +298,7 @@ module ActionView # # " # # - # <%= button_to('Destroy', 'http://www.example.com', :confirm => 'Are you sure?', + # <%= button_to('Destroy', 'http://www.example.com', :confirm => 'Are you sure?', # :method => "delete", :remote => true, :disable_with => 'loading...') %> # # => "
# #
@@ -546,8 +562,14 @@ module ActionView # current_page?(:controller => 'library', :action => 'checkout') # # => false def current_page?(options) + unless request + raise "You cannot use helpers that need to determine the current " \ + "page unless your view context provides a Request object " \ + "in a #request method" + end + url_string = CGI.unescapeHTML(url_for(options)) - request = controller.request + # We ignore any extra parameters in the request_uri if the # submitted url doesn't have any either. This lets the function # work with things like ?order=asc diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index 23b0c6e121..ddea9cfd92 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -142,8 +142,13 @@ module ActionView end end + def _router + @controller._router if @controller.respond_to?(:_router) + end + def method_missing(selector, *args) - if @controller._router.named_routes.helpers.include?(selector) + if @controller.respond_to?(:_router) && + @controller._router.named_routes.helpers.include?(selector) @controller.__send__(selector, *args) else super -- cgit v1.2.3 From 10ad15861f5eb48c2634c94a62f51eb83e559f66 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sat, 3 Apr 2010 18:22:17 -0300 Subject: :action => "update" used in a non RESTful way confuses --- actionpack/lib/action_view/helpers/form_helper.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 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 6a14f0be9c..6aaaac57a6 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -121,7 +121,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 do |f| %> # <%= f.error_messages %> # First name: <%= f.text_field :first_name %>
# Last name : <%= f.text_field :last_name %>
@@ -145,7 +145,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 do |f| %> # ... # <% end %> # @@ -177,7 +177,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 do |f| %> # First name: <%= f.text_field :first_name %> # Last name : <%= f.text_field :last_name %> # Biography : <%= text_area :person, :biography %> @@ -265,7 +265,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, :builder => LabellingFormBuilder do |f| %> # <%= f.text_field :first_name %> # <%= f.text_field :last_name %> # <%= text_area :person, :biography %> @@ -342,7 +342,7 @@ module ActionView # # === Generic Examples # - # <%= form_for @person, :url => { :action => "update" } do |person_form| %> + # <%= form_for @person do |person_form| %> # First name: <%= person_form.text_field :first_name %> # Last name : <%= person_form.text_field :last_name %> # @@ -404,7 +404,7 @@ 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 do |person_form| %> # ... # <%= person_form.fields_for :address do |address_fields| %> # Street : <%= address_fields.text_field :street %> @@ -433,7 +433,7 @@ 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 do |person_form| %> # ... # <%= person_form.fields_for :address do |address_fields| %> # ... @@ -461,7 +461,7 @@ 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 do |person_form| %> # ... # <%= person_form.fields_for :projects do |project_fields| %> # <% if project_fields.object.active? %> @@ -472,7 +472,7 @@ 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 do |person_form| %> # ... # <% @person.projects.each do |project| %> # <% if project.active? %> @@ -485,7 +485,7 @@ module ActionView # # Or a collection to be used: # - # <%= form_for @person, :url => { :action => "update" } do |person_form| %> + # <%= form_for @person do |person_form| %> # ... # <%= person_form.fields_for :projects, @active_projects do |project_fields| %> # Name: <%= project_fields.text_field :name %> @@ -514,7 +514,7 @@ 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 do |person_form| %> # ... # <%= person_form.fields_for :projects do |project_fields| %> # Delete: <%= project_fields.check_box :_destroy %> -- cgit v1.2.3 From 8f9becb42632d68ae84639b19022ff7d64666a30 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sat, 3 Apr 2010 18:34:28 -0300 Subject: :action => "create" added to form_for with name only to show appropiate behavior --- actionpack/lib/action_view/helpers/form_helper.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 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 6aaaac57a6..9467a0912a 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -121,7 +121,7 @@ module ActionView # The generic way to call +form_for+ yields a form builder around a # model: # - # <%= form_for :person do |f| %> + # <%= form_for :person, :url => { :action => "create" } do |f| %> # <%= f.error_messages %> # First name: <%= f.text_field :first_name %>
# Last name : <%= f.text_field :last_name %>
@@ -145,7 +145,7 @@ module ActionView # If the instance variable is not @person you can pass the actual # record as the second argument: # - # <%= form_for :person, person do |f| %> + # <%= form_for :person, person, :url => { :action => "create" } do |f| %> # ... # <% end %> # @@ -177,7 +177,7 @@ module ActionView # possible to use both the stand-alone FormHelper methods and methods # from FormTagHelper. For example: # - # <%= form_for :person, @person do |f| %> + # <%= form_for :person, @person, :url => { :action => "create" } do |f| %> # First name: <%= f.text_field :first_name %> # Last name : <%= f.text_field :last_name %> # Biography : <%= text_area :person, :biography %> @@ -265,7 +265,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, :builder => LabellingFormBuilder do |f| %> + # <%= form_for :person, @person, :url => { :action => "create" }, :builder => LabellingFormBuilder do |f| %> # <%= f.text_field :first_name %> # <%= f.text_field :last_name %> # <%= text_area :person, :biography %> @@ -354,13 +354,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, :url => { :action => "create" } 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, :url => { :action => "create" } do |permission_fields| %> # Admin?: <%= permission_fields.check_box :admin %> # <% end %> # -- cgit v1.2.3