Skip to content

Fix generating nested models #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix generating nested models
Tis PR fixes error when generating nested models such as:

`bin/rails g scaffold admin/role name description`
  • Loading branch information
dixpac committed Dec 3, 2022
commit 9f0659adf728de4872f3dede77200142da3dbfd4
4 changes: 2 additions & 2 deletions lib/generators/tailwindcss/scaffold/scaffold_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def copy_view_files
end
end

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

private
Expand All @@ -31,4 +31,4 @@ def available_views
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<div id="<%%= dom_id <%= singular_table_name %> %>">
<div id="<%%= dom_id <%= singular_name %> %>">
<% attributes.reject(&:password_digest?).each do |attribute| -%>
<p class="my-5">
<strong class="block font-medium mb-1"><%= attribute.human_name %>:</strong>
<% if attribute.attachment? -%>
<%%= link_to <%= singular_table_name %>.<%= attribute.column_name %>.filename, <%= singular_table_name %>.<%= attribute.column_name %> if <%= singular_table_name %>.<%= attribute.column_name %>.attached? %>
<%%= link_to <%= singular_name %>.<%= attribute.column_name %>.filename, <%= singular_name %>.<%= attribute.column_name %> if <%= singular_name %>.<%= attribute.column_name %>.attached? %>
<% elsif attribute.attachments? -%>
<%% <%= singular_table_name %>.<%= attribute.column_name %>.each do |<%= attribute.singular_name %>| %>
<%% <%= singular_name %>.<%= attribute.column_name %>.each do |<%= attribute.singular_name %>| %>
<div><%%= link_to <%= attribute.singular_name %>.filename, <%= attribute.singular_name %> %></div>
<%% end %>
<% else -%>
<%%= <%= singular_table_name %>.<%= attribute.column_name %> %>
<%%= <%= singular_name %>.<%= attribute.column_name %> %>
<% end -%>
</p>

<% end -%>
<%% if action_name != "show" %>
<%%= link_to "Show this <%= human_name.downcase %>", <%= singular_table_name %>, class: "rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
<%%= 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" %>
<%%= link_to "Show this <%= human_name.downcase %>", <%= singular_name %>, class: "rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
<%%= 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" %>
<hr class="mt-6">
<%% end %>
</div>
6 changes: 6 additions & 0 deletions test/lib/generators/tailwindcss/scaffold_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ class Tailwindcss::Generators::ScaffoldGeneratorTest < Rails::Generators::TestCa

%w(index edit new show _form _message).each { |view| assert_file "app/views/messages/#{view}.html.erb" }
end

test "with namespace invoked" do
run_generator [ "admin/role", "name:string", "description:string" ]

%w(index edit new show _form _role).each { |view| assert_file "app/views/admin/roles/#{view}.html.erb" }
end
end