Skip to content

Commit

Permalink
Add flash
Browse files Browse the repository at this point in the history
  • Loading branch information
hunchr committed Nov 5, 2024
1 parent 738d308 commit ed36769
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
14 changes: 10 additions & 4 deletions app/controllers/hotsheet/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ def broadcast_edit_intent
})
end

def update
record = model.find(params[:id])
notice = "#{record} #{record.update(model_params) ? "updated successfully" : "update failed"}"
def update # rubocop:disable Metrics/AbcSize
record = model.find params[:id]

redirect_to polymorphic_path(record), notice: notice
if record.update model_params
flash[:notice] = t("hotsheet.success", record: record)
else
flash[:alert] = t("hotsheet.error", record: record,
errors: record.errors.full_messages.join(", "))
end

redirect_to "#{root_path}#{model.table_name}"
end

private
Expand Down
7 changes: 7 additions & 0 deletions app/views/layouts/hotsheet/_flash.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<%# locals: () %>

<% flash.each do |type, msg| %>
<div class='flash <%= type %>'>
<span><%= msg %></span>
</div>
<% end %>
2 changes: 2 additions & 0 deletions app/views/layouts/hotsheet/_sidebar.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<%# locals: () %>

<aside class="sidebar">
<nav>
<ul class="nav-list">
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/hotsheet/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
</head>
<body>
<%= render "layouts/hotsheet/sidebar" %>
<%= render "layouts/hotsheet/flash" %>
<main>
<%= yield %>
</main>
Expand Down
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
en:
home: Home
hotsheet:
success: '%{record} updated successfully'
error: '%{record} update failed: %{errors}'

0 comments on commit ed36769

Please sign in to comment.