aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZachary Scott <zachary@zacharyscott.net>2013-07-23 15:54:12 -0400
committerSantiago Pastorino <santiago@wyeworks.com>2013-07-23 18:06:44 -0300
commitb017562382e1c43655eec3456d2a78c1d4407952 (patch)
tree65b23cab9b2920bc0c75b4928ba3aaf5f963ec13
parenteb8d48eb3ea27b7a7470eb9668748abd4914386b (diff)
downloadrails-b017562382e1c43655eec3456d2a78c1d4407952.tar.gz
rails-b017562382e1c43655eec3456d2a78c1d4407952.tar.bz2
rails-b017562382e1c43655eec3456d2a78c1d4407952.zip
Use GeneratedAttribute#column_name if #reference? scaffold_generator in _form view [Fixes #11573]
-rw-r--r--railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb5
-rw-r--r--railties/test/generators/scaffold_generator_test.rb24
2 files changed, 29 insertions, 0 deletions
diff --git a/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb b/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb
index 1799e823b6..4a40ba654d 100644
--- a/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb
+++ b/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb
@@ -21,8 +21,13 @@
<%%= f.label :password_confirmation %><br>
<%%= f.password_field :password_confirmation %>
<% else -%>
+ <% if attribute.reference? -%>
+ <%%= f.label :<%= attribute.column_name %> %><br>
+ <%%= f.<%= attribute.field_type %> :<%= attribute.column_name %> %>
+ <% else -%>
<%%= f.label :<%= attribute.name %> %><br>
<%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
+ <% end -%>
<% end -%>
</div>
<% end -%>
diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb
index d5ad978986..4b837da483 100644
--- a/railties/test/generators/scaffold_generator_test.rb
+++ b/railties/test/generators/scaffold_generator_test.rb
@@ -286,6 +286,30 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
end
end
+ def test_scaffold_generator_belongs_to
+ run_generator ["account", "name", "currency:belongs_to"]
+
+ assert_file "app/models/account.rb", /belongs_to :currency/
+
+ assert_migration "db/migrate/create_accounts.rb" do |m|
+ assert_method :change, m do |up|
+ assert_match(/t\.string :name/, up)
+ assert_match(/t\.belongs_to :currency/, up)
+ end
+ end
+
+ assert_file "app/controllers/accounts_controller.rb" do |content|
+ assert_instance_method :account_params, content do |m|
+ assert_match(/permit\(:name, :currency_id\)/, m)
+ end
+ end
+
+ assert_file "app/views/accounts/_form.html.erb" do |content|
+ assert_match(/<%= f\.text_field :name %>/, content)
+ assert_match(/<%= f\.text_field :currency_id %>/, content)
+ end
+ end
+
def test_scaffold_generator_password_digest
run_generator ["user", "name", "password:digest"]