mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #13434 from tanraya/local_variables
Use local variables in _form.html.erb generated by scaffold. Conflicts: railties/CHANGELOG.md
This commit is contained in:
commit
1468a11f9b
5 changed files with 21 additions and 6 deletions
|
@ -1,3 +1,7 @@
|
|||
* Use local variables in `_form.html.erb` partial generated by scaffold.
|
||||
|
||||
*Andrew Kozlov*
|
||||
|
||||
* Add `config/initializers/callback_terminator.rb`
|
||||
|
||||
Newly generated Rails apps have a new initializer called
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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 %>
|
||||
|
|
|
@ -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 %>
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
Loading…
Reference in a new issue