Skip to content

Instantly share code, notes, and snippets.

@carlosramireziii
Created October 27, 2016 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosramireziii/644ff5cabca9a1ba527686a0c2c3c61e to your computer and use it in GitHub Desktop.
Save carlosramireziii/644ff5cabca9a1ba527686a0c2c3c61e to your computer and use it in GitHub Desktop.
class TicketReportPresenter
def ticket_report
return if @model.tickets.empty?
safe_join([header, table])
end
def header
content_tag(:h4, "Users have tickets")
end
def table
content_tag(:table, safe_join([table_header, table_body]))
end
def table_header
content_tag(:thead) do
safe_join([
content_tag(:th, "User Email"),
content_tag(:th, "Reason(s)")
])
end
end
def table_body
content_tag(:tbody, table_rows)
end
def table_rows
tickets = @model.unpayable_tickets.map { |ticket| table_row(ticket) }
safe_join(tickets)
end
def table_row(ticket)
content_tag(:tr) do
safe_join([
content_tag(:td, ticket.email),
content_tag(:td, reasons_list(ticket.reasons))
])
end
end
def reasons_list(reasons)
reasons = reasons.map { |reason| reason_list_item(reason) }
content_tag(:ul, safe_join(reasons))
end
def reason_list_item(reason)
content_tag(:li, reason)
end
end
@bastianwegge
Copy link

awesome implementation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment