Skip to content

Commit d8975b4

Browse files
committed
feat(blocks): update create and update actions for better resource handling; enhance show view with action buttons
1 parent 3e3f8b6 commit d8975b4

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

app/controllers/better_together/content/blocks_controller.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ def index
1717
end
1818

1919
def create
20-
@block = resource_class.new(block_params)
20+
@block = resource_instance(block_params)
21+
authorize_resource
2122

2223
if @block.save
2324
redirect_to content_block_path(@block),
@@ -30,7 +31,7 @@ def create
3031
def update # rubocop:todo Metrics/MethodLength
3132
respond_to do |format|
3233
if @block.update(block_params)
33-
redirect_to edit_content_block_path(@block),
34+
redirect_to content_block_path(@block),
3435
notice: t('flash.generic.updated', resource: t('resources.block'))
3536
else
3637
format.turbo_stream do

app/views/better_together/content/blocks/show.html.erb

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,29 @@
88
<%= render @block %>
99
</div>
1010
<div class="card-footer">
11-
<%= link_to content_blocks_path, class: 'btn btn-outline-info me-2', 'aria-label' => t('globals.back_to_list') do %>
12-
<i class="fas fa-arrow-left"></i> <%= t('globals.back_to_list') %>
13-
<% end %>
14-
<%= link_to edit_content_block_path(@block), class: 'btn btn-outline-secondary', 'aria-label' => t('globals.edit') do %>
15-
<i class="fas fa-edit"></i> <%= t('globals.edit') %>
16-
<% end %>
11+
<div class="btn-toolbar" role="toolbar" aria-label="Block actions toolbar">
12+
<div class="btn-group me-2" role="group" aria-label="Navigation actions">
13+
<%= link_to content_blocks_path, class: 'btn btn-outline-info', 'aria-label' => t('globals.back_to_list') do %>
14+
<i class="fas fa-arrow-left"></i> <%= t('globals.back_to_list') %>
15+
<% end %>
16+
</div>
17+
18+
<% if policy(@block).edit? %>
19+
<div class="btn-group me-2" role="group" aria-label="Edit actions">
20+
<%= link_to edit_content_block_path(@block), class: 'btn btn-outline-secondary', 'aria-label' => t('globals.edit') do %>
21+
<i class="fas fa-edit"></i> <%= t('globals.edit') %>
22+
<% end %>
23+
</div>
24+
<% end %>
25+
26+
<% if policy(@block).destroy? %>
27+
<div class="btn-group" role="group" aria-label="Delete actions">
28+
<%= button_to content_block_path(@block), method: :delete, data: { turbo_confirm: t('globals.confirm_delete') }, class: 'btn btn-danger', 'aria-label' => t('globals.delete') do %>
29+
<i class="fas fa-trash"></i> <%= t('globals.delete') %>
30+
<% end %>
31+
</div>
32+
<% end %>
33+
</div>
1734
</div>
1835
</div>
1936
</div>

0 commit comments

Comments
 (0)