mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
changed from :object_name to :as on form_for api
This commit is contained in:
parent
1f7b4447a9
commit
d270da569e
3 changed files with 15 additions and 19 deletions
|
@ -300,16 +300,16 @@ module ActionView
|
|||
|
||||
case record_or_name_or_array
|
||||
when String, Symbol
|
||||
ActiveSupport::Deprecation.warn("Use the option :object_name => ... instead of a Symbol or String as a the first argument", caller)
|
||||
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
|
||||
when Array
|
||||
object = record_or_name_or_array.last
|
||||
object_name = options[:object_name] || ActionController::RecordIdentifier.singular_class_name(object)
|
||||
object_name = options[:as] || ActionController::RecordIdentifier.singular_class_name(object)
|
||||
apply_form_for_options!(record_or_name_or_array, options)
|
||||
args.unshift object
|
||||
else
|
||||
object = record_or_name_or_array
|
||||
object_name = options[:object_name] || ActionController::RecordIdentifier.singular_class_name(object)
|
||||
object_name = options[:as] || ActionController::RecordIdentifier.singular_class_name(object)
|
||||
apply_form_for_options!([object], options)
|
||||
args.unshift object
|
||||
end
|
||||
|
@ -327,12 +327,12 @@ module ActionView
|
|||
|
||||
html_options =
|
||||
if object.respond_to?(:persisted?) && object.persisted?
|
||||
{ :class => options[:object_name] ? "#{options[:object_name]}_edit" : dom_class(object, :edit),
|
||||
:id => options[:object_name] ? "#{options[:object_name]}_edit" : dom_id(object, :edit),
|
||||
{ :class => options[:as] ? "#{options[:as]}_edit" : dom_class(object, :edit),
|
||||
:id => options[:as] ? "#{options[:as]}_edit" : dom_id(object, :edit),
|
||||
:method => :put }
|
||||
else
|
||||
{ :class => options[:object_name] ? "#{options[:object_name]}_new" : dom_class(object, :new),
|
||||
:id => options[:object_name] ? "#{options[:object_name]}_new" : dom_id(object),
|
||||
{ :class => options[:as] ? "#{options[:as]}_new" : dom_class(object, :new),
|
||||
:id => options[:as] ? "#{options[:as]}_new" : dom_id(object),
|
||||
:method => :post }
|
||||
end
|
||||
|
||||
|
|
|
@ -8,4 +8,4 @@ module ERBTest
|
|||
assert_equal "<form action=\"/blah/update\" method=\"post\"></form>", output
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -440,7 +440,7 @@ class FormHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_form_for_with_symbol_object_name
|
||||
form_for(@post, :object_name => "other_name", :html => { :id => 'create-post' }) do |f|
|
||||
form_for(@post, :as => "other_name", :html => { :id => 'create-post' }) do |f|
|
||||
concat f.label(:title)
|
||||
concat f.text_field(:title)
|
||||
concat f.text_area(:body)
|
||||
|
@ -504,12 +504,10 @@ class FormHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_form_for_without_object
|
||||
assert_deprecated do
|
||||
form_for(:post, :html => { :id => 'create-post' }) do |f|
|
||||
concat f.text_field(:title)
|
||||
concat f.text_area(:body)
|
||||
concat f.check_box(:secret)
|
||||
end
|
||||
form_for(:post, :html => { :id => 'create-post' }) do |f|
|
||||
concat f.text_field(:title)
|
||||
concat f.text_area(:body)
|
||||
concat f.check_box(:secret)
|
||||
end
|
||||
|
||||
expected =
|
||||
|
@ -603,10 +601,8 @@ class FormHelperTest < ActionView::TestCase
|
|||
def test_submit_without_object_and_locale_strings
|
||||
old_locale, I18n.locale = I18n.locale, :submit
|
||||
|
||||
assert_deprecated do
|
||||
form_for(:post) do |f|
|
||||
concat f.submit :class => "extra"
|
||||
end
|
||||
form_for(:post) do |f|
|
||||
concat f.submit :class => "extra"
|
||||
end
|
||||
|
||||
expected = "<form action='http://www.example.com' method='post'>" +
|
||||
|
|
Loading…
Reference in a new issue