Use local variables in _form.html.erb generated by scaffold. #13434

Merged
merged 1 commit into from Jan 3, 2015

Projects

None yet

8 participants

@tanraya
Contributor
tanraya commented Dec 21, 2013

It seems a good idea to use local variables in generated partials instead of using instance variables.

Before

<%= render 'form' %>

After

<%= render 'form', product: @product %>
@carlosantoniodasilva carlosantoniodasilva commented on an outdated diff Dec 21, 2013
railties/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Use local variables in _form.html.erb generated by scaffold generator.
@carlosantoniodasilva
carlosantoniodasilva Dec 21, 2013 Member
`_form.html.erb` partial generated by scaffold.
@carlosantoniodasilva carlosantoniodasilva commented on the diff Dec 21, 2013
railties/test/generators/scaffold_generator_test.rb
@@ -68,6 +68,17 @@ def test_scaffold_on_invoke
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
@carlosantoniodasilva
carlosantoniodasilva Dec 21, 2013 Member

You can probably remove the _form file from line 66 since we're testing against the same file here again.

@carlosantoniodasilva
carlosantoniodasilva Dec 21, 2013 Member

Actually nevermind, leave it there.

@carlosantoniodasilva

👍

@dmathieu
Contributor

@tanraya can you squash your commits please? Also, they don't apply cleanly into master. You'll need to rebase.

@tanraya
Contributor
tanraya commented Dec 22, 2013

@dmathieu I will do.

@tanraya
Contributor
tanraya commented Dec 28, 2013

@dmathieu done

@senny senny commented on the diff Jan 6, 2014
railties/test/generators/scaffold_generator_test.rb
@@ -68,6 +68,17 @@ def test_scaffold_on_invoke
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)
@senny
senny Jan 6, 2014 Member

you should verify what should be there, not what shouldn't be there.

@carlosantoniodasilva
carlosantoniodasilva Jul 28, 2014 Member

👍 for @senny's comment.

@jamo
Contributor
jamo commented Feb 11, 2014

I added the suggested test case, see jamo@a0b548d

(all tests passes)

@arunagw
Member
arunagw commented Jul 4, 2014

@tanraya did you get some time to update this PR?

thanks

@tanraya
Contributor
tanraya commented Jul 25, 2014

@arunagw Yes. Updated now.

@arunagw
Member
arunagw commented Jul 25, 2014

@tanraya seems test broke. Can you see those as well ?

@carlosantoniodasilva carlosantoniodasilva commented on an outdated diff Jul 25, 2014
...ails/generators/erb/scaffold/templates/_form.html.erb
<ul>
<%% @<%= singular_table_name %>.errors.full_messages.each do |message| %>
<li><%%= message %></li>
- <%% end %>
@carlosantoniodasilva
carlosantoniodasilva Jul 25, 2014 Member

It seems this should not be removed.

@tanraya tanraya Use local variables in _form.html.erb generated by scaffold generator.
It seems a good idea to use local variables in generated partials instead of using instance variables.

Before

    <%= render 'form' %>

After

    <%= render 'form', product: @product %>
6bd8126
@tanraya
Contributor
tanraya commented Jul 26, 2014

@carlosantoniodasilva @arunagw Now its done. All tests passed.

@rafaelfranca rafaelfranca modified the milestone: 4.2.0, 5.0.0 Aug 18, 2014
@carlosantoniodasilva carlosantoniodasilva merged commit 6bd8126 into rails:master Jan 3, 2015

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details
@rafaelfranca rafaelfranca modified the milestone: 5.0.0 [temp], 5.0.0 Dec 30, 2015
@prathamesh-sonpatki prathamesh-sonpatki added a commit to prathamesh-sonpatki/rails that referenced this pull request Jun 11, 2016
@prathamesh-sonpatki prathamesh-sonpatki Add missing things to Rails 5.0 release notes [ci skip] 16fd249
@prathamesh-sonpatki prathamesh-sonpatki added a commit to prathamesh-sonpatki/rails that referenced this pull request Jun 11, 2016
@prathamesh-sonpatki prathamesh-sonpatki Add missing things to Rails 5.0 release notes [ci skip] 9f23b75
@christiannelson christiannelson added a commit to carbonfive/raygun-rails that referenced this pull request Jul 1, 2016
@christiannelson christiannelson Use local vars instead of instance vars
See rails/rails#13434 for reference.
9f6e8a6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment