Skip to content

Commit ade4e7a

Browse files
authored
Merge pull request rails#43365 from alpaca-tc/fixed_scaffold
Fixed bug that occurred when scaffold generated a model with nested namespace.
2 parents 5576ca2 + 293b25e commit ade4e7a

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

railties/lib/rails/generators/erb/scaffold/scaffold_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def copy_view_files
2222
end
2323
end
2424

25-
template "partial.html.erb", File.join("app/views", controller_file_path, "_#{singular_table_name}.html.erb")
25+
template "partial.html.erb", File.join("app/views", controller_file_path, "_#{singular_name}.html.erb")
2626
end
2727

2828
private
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
<div id="<%%= dom_id <%= singular_table_name %> %>">
1+
<div id="<%%= dom_id <%= singular_name %> %>">
22
<% attributes.reject(&:password_digest?).each do |attribute| -%>
33
<p>
44
<strong><%= attribute.human_name %>:</strong>
55
<% if attribute.attachment? -%>
6-
<%%= link_to <%= singular_table_name %>.<%= attribute.column_name %>.filename, <%= singular_table_name %>.<%= attribute.column_name %> if <%= singular_table_name %>.<%= attribute.column_name %>.attached? %>
6+
<%%= link_to <%= singular_name %>.<%= attribute.column_name %>.filename, <%= singular_name %>.<%= attribute.column_name %> if <%= singular_name %>.<%= attribute.column_name %>.attached? %>
77
<% elsif attribute.attachments? -%>
8-
<%% <%= singular_table_name %>.<%= attribute.column_name %>.each do |<%= attribute.singular_name %>| %>
8+
<%% <%= singular_name %>.<%= attribute.column_name %>.each do |<%= attribute.singular_name %>| %>
99
<div><%%= link_to <%= attribute.singular_name %>.filename, <%= attribute.singular_name %> %></div>
1010
<%% end %>
1111
<% else -%>
12-
<%%= <%= singular_table_name %>.<%= attribute.column_name %> %>
12+
<%%= <%= singular_name %>.<%= attribute.column_name %> %>
1313
<% end -%>
1414
</p>
1515

1616
<% end -%>
1717
<p>
18-
<%%= link_to "Show this <%= human_name.downcase %>", <%= singular_table_name %> %>
18+
<%%= link_to "Show this <%= human_name.downcase %>", <%= singular_name %> %>
1919
</p>
2020
</div>

railties/test/generators/scaffold_generator_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,12 @@ def test_scaffold_with_namespace_on_invoke
273273
assert_match(%("New role", new_admin_role_path), content)
274274
end
275275

276+
assert_file "app/views/admin/roles/_role.html.erb" do |content|
277+
assert_match(%("Show this role", role), content)
278+
assert_match "role", content
279+
assert_no_match "admin_role", content
280+
end
281+
276282
%w(edit new show _form).each do |view|
277283
assert_file "app/views/admin/roles/#{view}.html.erb"
278284
end

0 commit comments

Comments
 (0)