Reputation: 632
Why are some instance variables available in the view without the '@' symbol? Is it a convenience provided by Rails where instance variables matching the name of the controller are available or is something else at work here?
Ex:
picks_controller.rb
@pick = Pick.new
@show = Show.new
_form.html.erb
<%= pick.class %> // no exception raised
<%= show.class %> // "undefined local variable or method `show'" exception raised
Upvotes: 3
Views: 1022
Reputation: 632
This is a change in Rails 5. The default view file now passes a local variable to the form partial.
Instead of this...
new.html.erb
<%= render 'form' %>
This is the new default...
new.html.erb
<%= render 'form', person: @person %>
See this pull request for more info.
Upvotes: 5