Skip to content

Commit

Permalink
Extract partial for attrs table
Browse files Browse the repository at this point in the history
  • Loading branch information
jonallured authored and github-actions[bot] committed Feb 18, 2024
1 parent 271f7ed commit 4dcd946
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
9 changes: 9 additions & 0 deletions app/models/book.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@ def enhance!
}
update!(open_attrs)
end

def table_attrs
[
["ISBN", isbn],
["Finished On", finished_on],
["Title", title],
["Pages", pages]
]
end
end
8 changes: 8 additions & 0 deletions app/models/gift_idea.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@ class GiftIdea < ApplicationRecord
scope :claimed, -> { where("claimed_at IS NOT NULL AND received_at IS NULL") }
scope :received, -> { where("received_at IS NOT NULL") }
scope :not_received, -> { where("received_at IS NULL") }

def table_attrs
[
["Title", title],
["Website URL", website_url],
["Note", note]
]
end
end
15 changes: 1 addition & 14 deletions app/views/admin/books/edit.html.haml
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
%h1 Book #{book.id}

%table.w-full
%tbody
%tr
%td ISBN
%td.text-right= book.isbn
%tr
%td Finished On
%td.text-right= book.finished_on
%tr
%td Title
%td.text-right= book.title
%tr
%td Pages
%td.text-right= book.pages
= render partial: "attrs_table", locals: { attrs: book.table_attrs }

= render "form", book: book, button_label: "update"
12 changes: 1 addition & 11 deletions app/views/admin/gift_ideas/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,4 @@

%p= link_to "edit", edit_admin_gift_idea_path(gift_idea)

%table.w-full
%tbody
%tr
%td Title
%td.text-right= gift_idea.title
%tr
%td Website URL
%td.text-right= gift_idea.website_url
%tr
%td Note
%td.text-right= gift_idea.note
= render partial: "attrs_table", locals: { attrs: gift_idea.table_attrs }
6 changes: 6 additions & 0 deletions app/views/application/_attrs_table.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
%table.w-full
%tbody
- attrs.each do |(key, value)|
%tr
%td= key
%td.text-right= value

0 comments on commit 4dcd946

Please sign in to comment.