Tidy BubblesController

This commit is contained in:
Jeffrey Hardy
2024-09-13 18:45:26 -04:00
parent 7f45b8fe6e
commit 87cd9348f7
2 changed files with 16 additions and 21 deletions
+14 -18
View File
@@ -16,35 +16,31 @@ class BubblesController < ApplicationController
@bubble = Bubble.new
end
def edit
end
def update
@bubble.update(bubble_params)
remove_image if params[:remove_image] == "true"
redirect_to bubble_path(@bubble)
end
def create
@bubble = Bubble.create! bubble_params
redirect_to bubble_path(@bubble)
@bubble = Bubble.create!(bubble_params)
redirect_to @bubble
end
def show
end
def edit
end
def update
@bubble.update!(bubble_params)
@bubble.image.purge_later if params.key?(:remove_image)
redirect_to @bubble
end
private
def set_bubble
@bubble = Bubble.find(params[:id])
end
def bubble_params
params.require(:bubble).permit(:title, :body, :color, :due_on, :image, :remove_image, tag_ids: [])
end
def remove_image
@bubble.image.purge
params.require(:bubble).permit(:title, :body, :color, :due_on, :image, tag_ids: [])
end
end
+2 -3
View File
@@ -7,9 +7,8 @@
<% if bubble.image.attached? %>
<%= tag.label class: "btn btn--plain", style: "--btn-icon-size: 3em; margin-block-start: -0.5em; margin-inline-end: -0.2em", data: { action: "click->upload-preview#clear click->form#submit", upload_preview_target: "button" } do %>
<svg viewBox="0 0 24 20" xmlns="http://www.w3.org/2000/svg" fill="var(--bubble-color)"><path fill="var(--color-negative)" d="m19.1 0c-2.8 0-5 2.2-5 5s2.2 5 5 5 5-2.2 5-5-2.2-5-5-5zm-.8 5.7h-1.2c-.3 0-.6-.3-.6-.6s.3-.6.6-.6h1.2s1.6 0 1.6 0h1.2c.3 0 .6.3.6.6s-.3.6-.6.6h-1.2s-1.6 0-1.6 0z"/><path d="m6.7 10.5c.9 0 1.6-.7 1.6-1.6s-.7-1.6-1.6-1.6-1.6.7-1.6 1.6.7 1.6 1.6 1.6z" fill="none"/><path d="m9.7 16.9h.1l-.1-.1z"/><path d="m19.2 11.6v6.3c0 .2 0 .4-.4.4h-16.8v-13.7c0-.2 0-.4.4-.4h10.1c0-.7.3-1.3.5-1.8h-11.6c-.9.2-1.4.9-1.4 1.8v14c0 1 .8 1.8 1.8 1.8h17.5c1 0 1.8-.8 1.8-1.8v-6.9c-.6.2-1.2.3-1.8.3z"/><path d="m4.8 5.5c-.7 0-1.3.6-1.3 1.3v8.9c0 .4.2.7.5 1l2.6-3.5c.2-.3.6-.5.9-.5s0 0 0 0c.4 0 .7.2.9.5l.9 1.3 2.3-3.5c.3-.4.8-.7 1.3-.7s0 0 0 0c.5 0 1 .3 1.3.7l3.1 5c0-.1 0-.2 0-.3v-4.2c-2.8-.6-4.9-3-5.1-6h-7.6zm1.9 5c-.9 0-1.6-.7-1.6-1.6s.7-1.6 1.6-1.6 1.6.7 1.6 1.6-.7 1.6-1.6 1.6z"/><path d="m5.2 16.9h2.6l1-1.5-1.2-1.7z"/><path d="m10.4 15.8-.7 1 .1.1h1.3 5.1l-3.1-5.1z"/></svg>
<%= form.hidden_field :bubble, value: bubble.id %>
<%= check_box_tag "remove_image", "true" %>
<span class="for-screen-reader">Remove imagee</span>
<%= check_box_tag :remove_image, true %>
<span class="for-screen-reader">Remove image</span>
<% end %>
<% else %>
<label class="btn btn--plain input--file" style="--btn-icon-size: 3em; margin-block-start: -0.5em; margin-inline-end: -0.2em">