1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #12112 from adamniedzielski/fix-form-for-namespace-and-as

form_for - fix :namespace and :as options clash

Conflicts:
	actionview/CHANGELOG.md
This commit is contained in:
Rafael Mendonça França 2013-09-12 18:20:14 -03:00
commit 495daef061
3 changed files with 21 additions and 1 deletions

View file

@ -1,3 +1,10 @@
* Fix `form_for` when both `namespace` and `as` options are present
`as` option no longer overwrites `namespace` option when generating
html id attribute of the form element
*Adam Niedzielski*
* Fix `excerpt` when `:separator` is `nil`.
*Paul Nikitochkin*

View file

@ -442,10 +442,11 @@ module ActionView
object = convert_to_model(object)
as = options[:as]
namespace = options[:namespace]
action, method = object.respond_to?(:persisted?) && object.persisted? ? [:edit, :patch] : [:new, :post]
options[:html].reverse_merge!(
class: as ? "#{action}_#{as}" : dom_class(object, action),
id: as ? "#{action}_#{as}" : [options[:namespace], dom_id(object, action)].compact.join("_").presence,
id: (as ? [namespace, action, as] : [namespace, dom_id(object, action)]).compact.join("_").presence,
method: method
)

View file

@ -1681,6 +1681,18 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal expected, output_buffer
end
def test_form_for_with_namespace_and_as_option
form_for(@post, namespace: 'namespace', as: 'custom_name') do |f|
concat f.text_field(:title)
end
expected = whole_form('/posts/123', 'namespace_edit_custom_name', 'edit_custom_name', method: 'patch') do
"<input id='namespace_custom_name_title' name='custom_name[title]' type='text' value='Hello World' />"
end
assert_dom_equal expected, output_buffer
end
def test_two_form_for_with_namespace
form_for(@post, namespace: 'namespace_1') do |f|
concat f.label(:title)