提交 1468a11f 编写于 作者: C Carlos Antonio da Silva

Merge pull request #13434 from tanraya/local_variables

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

Conflicts:
	railties/CHANGELOG.md
* 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
......
<%%= 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>
......
<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 %>
<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 @@ 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
%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"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册