Skip to content

make the index a table again #457

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

Closed
wants to merge 2 commits into from
Closed
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
44 changes: 37 additions & 7 deletions lib/generators/tailwindcss/scaffold/templates/index.html.erb.tt
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,44 @@
<%%= link_to "New <%= human_name.downcase %>", new_<%= singular_route_name %>_path, class: "rounded-md px-3.5 py-2.5 bg-blue-600 hover:bg-blue-500 text-white block font-medium" %>
</div>

<div id="<%= plural_table_name %>" class="min-w-full">
<div id="<%= plural_table_name %>" class="inline-block min-w-full mt-10">
<%% if @<%= plural_table_name %>.any? %>
<%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
<%%= render <%= singular_table_name %> %>
<p>
<%%= link_to "Show this <%= human_name.downcase %>", <%= model_resource_name(singular_table_name) %>, class: "ml-2 rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %>
</p>
<%% end %>
<table class="min-w-full divide-y divide-gray-300">
<thead>
<tr>
<% attributes.reject(&:password_digest?).each do |attribute| -%>
<th class="py-3.5 text-left font-semibold"><%= attribute.human_name %></th>
<% end -%>
<th class="py-3.5 text-left font-semibold">Actions</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200">
<%% @<%= plural_table_name %>.each do |<%= singular_name %>| %>
<tr class="border-b">
<% attributes.reject(&:password_digest?).each do |attribute| -%>
<% if attribute.attachment? -%>
<td class="py-4 whitespace-nowrap"><%%= link_to <%= singular_name %>.<%= attribute.column_name %>.filename, <%= singular_name %>.<%= attribute.column_name %> if <%= singular_name %>.<%= attribute.column_name %>.attached? %></td>
<% elsif attribute.attachments? -%>
<td class="py-4 whitespace-nowrap">
<%% <%= singular_name %>.<%= attribute.column_name %>.each do |<%= attribute.singular_name %>| %>
<div><%%= link_to <%= attribute.singular_name %>.filename, <%= attribute.singular_name %> %></div>
<%% end %>
</td>
<% else -%>
<td class="py-4 whitespace-nowrap"><%%= <%= singular_name %>.<%= attribute.column_name %> %></td>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The partial has logic to handle rendering links to attachments, which we should probably mirror.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch - added!

<% end -%>
<% end -%>
<td class="py-4 space-x-4 whitespace-nowrap">
<%%= link_to "Show", <%= model_resource_name(singular_table_name) %>, class: "text-blue-600 hover:text-blue-900" %>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept just the link to the show action, but we can also add the Edit and Destroy links. thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would personally like to have the Edit and Destroy links in the table, but I suppose we could do that in a separate PR if you're unsure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a nice addition - added!

<%%= link_to "Edit", edit_<%= singular_route_name %>_path(<%= singular_table_name %>), class: "text-blue-600 hover:text-blue-900" %>
<div class="inline-block ml-2">
<%%= button_to "Destroy", <%= model_resource_name %>, method: :delete, class: "text-red-600 hover:text-red-900" %>
</div>
</td>
</tr>
<%% end %>
</tbody>
</table>
<%% else %>
<p class="text-center my-10">No <%= human_name.downcase.pluralize %> found.</p>
<%% end %>
Expand Down
2 changes: 1 addition & 1 deletion test/integration/user_journey_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fi

# TEST: presence of the generated file
bin/rails generate scaffold post title:string body:text published:boolean
grep -q "Show this post" app/views/posts/index.html.erb
grep -q "Show" app/views/posts/index.html.erb

# TEST: contents of the css file
bin/rails tailwindcss:build[verbose]
Expand Down
Loading