diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-08-10 20:09:21 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-08-10 20:09:21 -0700 |
commit | a6e0d8cfcf483a88c9feda8a28b187043f5fab05 (patch) | |
tree | a42e762f60474c1a12a1cda36df1bf806ed7300f /actionpack | |
parent | feff27d38a1db9d16b06a261bdbe6d0f4683e976 (diff) | |
parent | 60b650b18c82a050ab81f924e23f7d308ffd8972 (diff) | |
download | rails-a6e0d8cfcf483a88c9feda8a28b187043f5fab05.tar.gz rails-a6e0d8cfcf483a88c9feda8a28b187043f5fab05.tar.bz2 rails-a6e0d8cfcf483a88c9feda8a28b187043f5fab05.zip |
Merge pull request #7314 from schneems/schneems/form_for_error
Check for Blank Record in form_for
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view/helpers/form_helper.rb | 1 | ||||
-rw-r--r-- | actionpack/test/template/form_helper_test.rb | 14 |
2 files changed, 15 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 5cfcfdd8d5..5dc5bb8a98 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -423,6 +423,7 @@ module ActionView object = nil else object = record.is_a?(Array) ? record.last : record + raise ArgumentError, "First argument in form cannot contain nil or be empty" if object.blank? object_name = options[:as] || model_name_from_record_or_class(object).param_key apply_form_for_options!(record, object, options) end diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 152b35ff0f..5c6cb45530 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -1045,6 +1045,20 @@ class FormHelperTest < ActionView::TestCase end end + def test_form_for_requires_arguments + error = assert_raises(ArgumentError) do + form_for(nil, :html => { :id => 'create-post' }) do + end + end + assert_equal "First argument in form cannot contain nil or be empty", error.message + + error = assert_raises(ArgumentError) do + form_for([nil, nil], :html => { :id => 'create-post' }) do + end + end + assert_equal "First argument in form cannot contain nil or be empty", error.message + end + def test_form_for form_for(@post, :html => { :id => 'create-post' }) do |f| concat f.label(:title) { "The Title" } |