Skip to content

Commit e14d23a

Browse files
authored
Fix generating nested models (rails#229)
Tis PR fixes error when generating nested models such as: `bin/rails g scaffold admin/role name description`
1 parent a94491d commit e14d23a

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

lib/generators/tailwindcss/scaffold/scaffold_generator.rb

+2-2
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
@@ -31,4 +31,4 @@ def available_views
3131
end
3232
end
3333
end
34-
end
34+
end
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
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 class="my-5">
44
<strong class="block font-medium mb-1"><%= 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
<%% if action_name != "show" %>
18-
<%%= link_to "Show this <%= human_name.downcase %>", <%= singular_table_name %>, class: "rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
19-
<%%= link_to 'Edit this <%= human_name.downcase %>', edit_<%= singular_table_name %>_path(<%= singular_table_name %>), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %>
18+
<%%= link_to "Show this <%= human_name.downcase %>", <%= singular_name %>, class: "rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
19+
<%%= link_to 'Edit this <%= human_name.downcase %>', edit_<%= singular_name %>_path(<%= singular_name %>), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %>
2020
<hr class="mt-6">
2121
<%% end %>
2222
</div>

test/lib/generators/tailwindcss/scaffold_generator_test.rb

+6
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@ class Tailwindcss::Generators::ScaffoldGeneratorTest < Rails::Generators::TestCa
1212

1313
%w(index edit new show _form _message).each { |view| assert_file "app/views/messages/#{view}.html.erb" }
1414
end
15+
16+
test "with namespace invoked" do
17+
run_generator [ "admin/role", "name:string", "description:string" ]
18+
19+
%w(index edit new show _form _role).each { |view| assert_file "app/views/admin/roles/#{view}.html.erb" }
20+
end
1521
end

0 commit comments

Comments
 (0)