diff options
Diffstat (limited to 'railties')
5 files changed, 21 insertions, 6 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index e9abfac7a0..36b26b9bd9 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,7 @@ +* Use local variables in `_form.html.erb` partial generated by scaffold. + + *Andrew Kozlov* + * Add `Rails::Application.config_for` to load a configuration for the current environment. 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 da99e74435..fa73fef5f7 100644 --- a/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb +++ b/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb @@ -1,10 +1,10 @@ -<%%= form_for(@<%= singular_table_name %>) do |f| %> - <%% if @<%= singular_table_name %>.errors.any? %> +<%%= form_for(<%= singular_table_name %>) do |f| %> + <%% if <%= singular_table_name %>.errors.any? %> <div id="error_explanation"> - <h2><%%= pluralize(@<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2> + <h2><%%= pluralize(<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2> <ul> - <%% @<%= singular_table_name %>.errors.full_messages.each do |message| %> + <%% <%= singular_table_name %>.errors.full_messages.each do |message| %> <li><%%= message %></li> <%% end %> </ul> diff --git a/railties/lib/rails/generators/erb/scaffold/templates/edit.html.erb b/railties/lib/rails/generators/erb/scaffold/templates/edit.html.erb index 5620fcc850..81329473d9 100644 --- a/railties/lib/rails/generators/erb/scaffold/templates/edit.html.erb +++ b/railties/lib/rails/generators/erb/scaffold/templates/edit.html.erb @@ -1,6 +1,6 @@ <h1>Editing <%= singular_table_name.titleize %></h1> -<%%= render 'form' %> +<%%= render 'form', <%= singular_table_name %>: @<%= singular_table_name %> %> <%%= link_to 'Show', @<%= singular_table_name %> %> | <%%= link_to 'Back', <%= index_helper %>_path %> diff --git a/railties/lib/rails/generators/erb/scaffold/templates/new.html.erb b/railties/lib/rails/generators/erb/scaffold/templates/new.html.erb index db13a5d870..9b2b2f4875 100644 --- a/railties/lib/rails/generators/erb/scaffold/templates/new.html.erb +++ b/railties/lib/rails/generators/erb/scaffold/templates/new.html.erb @@ -1,5 +1,5 @@ <h1>New <%= singular_table_name.titleize %></h1> -<%%= render 'form' %> +<%%= render 'form', <%= singular_table_name %>: @<%= singular_table_name %> %> <%%= link_to 'Back', <%= index_helper %>_path %> diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index 524bbde2b7..c44ce32122 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -68,6 +68,17 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase end assert_no_file "app/views/layouts/product_lines.html.erb" + # Views local variables + assert_file "app/views/product_lines/_form.html.erb" do |test| + assert_no_match(/@product_line/, test) + end + + %w(edit new).each do |view| + assert_file "app/views/product_lines/#{view}.html.erb" do |test| + assert_match(/product_line: @product_line/, test) + end + end + # Helpers assert_file "app/helpers/product_lines_helper.rb" assert_file "test/helpers/product_lines_helper_test.rb" |