diff options
author | wycats <wycats@gmail.com> | 2010-08-31 20:59:30 +0900 |
---|---|---|
committer | wycats <wycats@gmail.com> | 2010-09-09 18:24:33 -0700 |
commit | 74b49e87bb17077dff70911f68fe59ca34ee6993 (patch) | |
tree | 14b8d77010f554e0146d676df95589c8a9bcd6e9 /actionpack/lib/action_view/helpers | |
parent | e0e3adff0333cb23a63d61a2005cfc44f7f40b52 (diff) | |
download | rails-74b49e87bb17077dff70911f68fe59ca34ee6993.tar.gz rails-74b49e87bb17077dff70911f68fe59ca34ee6993.tar.bz2 rails-74b49e87bb17077dff70911f68fe59ca34ee6993.zip |
Simplify form_for by removing *args and extract_options! (at asakusa.rb)
Diffstat (limited to 'actionpack/lib/action_view/helpers')
-rw-r--r-- | actionpack/lib/action_view/helpers/form_helper.rb | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 43dbedc448..6d70c63de9 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -293,31 +293,32 @@ module ActionView # # If you don't need to attach a form to a model instance, then check out # FormTagHelper#form_tag. - def form_for(record_or_name_or_array, *args, &proc) + def form_for(record, record_object = nil, options = nil, &proc) raise ArgumentError, "Missing block" unless block_given? - options = args.extract_options! + options, record_object = record_object, nil if record_object.is_a?(Hash) + options ||= {} - case record_or_name_or_array + case record when String, Symbol - ActiveSupport::Deprecation.warn("Using form_for(:name, @resource) is deprecated. Please use form_for(@resource, :as => :name) instead.", caller) unless args.empty? - object_name = record_or_name_or_array + ActiveSupport::Deprecation.warn("Using form_for(:name, @resource) is deprecated. Please use form_for(@resource, :as => :name) instead.", caller) if record_object + object_name = record + object = record_object when Array - object = record_or_name_or_array.last - object_name = options[:as] || ActiveModel::Naming.param_key(object) - apply_form_for_options!(record_or_name_or_array, options) - args.unshift object + object = record.last + object_name = options[:as] || ActiveModel::Naming.singular(object) + apply_form_for_options!(record, options) else - object = record_or_name_or_array - object_name = options[:as] || ActiveModel::Naming.param_key(object) + object = record + object_name = options[:as] || ActiveModel::Naming.singular(object) apply_form_for_options!([object], options) - args.unshift object end - (options[:html] ||= {})[:remote] = true if options.delete(:remote) + options[:html] ||= {} + options[:html][:remote] = options.delete(:remote) - output = form_tag(options.delete(:url) || {}, options.delete(:html) || {}) - output << fields_for(object_name, *(args << options), &proc) + output = form_tag(options.delete(:url) || {}, options.delete(:html) || {}) + output << fields_for(object_name, object, options, &proc) output.safe_concat('</form>') end |