Skip to content

Commit

Permalink
bug fix with updating. Might revisit to see if can be improved but se…
Browse files Browse the repository at this point in the history
…ems to solve for now
  • Loading branch information
cjilbert504 committed Aug 11, 2023
1 parent 6a8564c commit adfe726
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
4 changes: 2 additions & 2 deletions app/controllers/tasks_controller.rb
Expand Up @@ -7,8 +7,8 @@ def destroy
task = Task.find(params[:id])
task.destroy
rescue ActiveRecord::RecordNotFound
task = params[:id]
task = Task.new(id: params[:id])
ensure
render turbo_stream: turbo_stream.remove(task)
render turbo_stream: turbo_stream.remove(task.id)
end
end
10 changes: 2 additions & 8 deletions app/helpers/application_helper.rb
@@ -1,11 +1,5 @@
module ApplicationHelper
def turbo_id_for(obj, id_or_hash: false)
id = if id_or_hash
obj.id
elsif obj.persisted?
dom_id(obj)
end

id || obj.hash
def turbo_id_for(obj)
obj.persisted? ? obj.id : obj.hash
end
end
4 changes: 2 additions & 2 deletions app/views/tasks/_task.html.erb
@@ -1,10 +1,10 @@
<%= fields_for "project[tasks_attributes][#{turbo_id_for(task)}]", task do |ff| %>
<fieldset class="mb-4" id="<%= turbo_id_for(task)%>">
<fieldset class="mb-4" id="<%= turbo_id_for(task) %>">
<legend>Task Info</legend>
<%= ff.label :name %><br>
<%= ff.text_field :name, class: "px-2 py-1 border w-full rounded-md" %>
<%= ff.hidden_field :id %>
<%= button_tag "Delete Task", formaction: task_path(turbo_id_for(task, id_or_hash: true)), formmethod: :delete, class: "mt-4 float-right p-2 rounded-md bg-red-300 hover:bg-red-400" %>
<%= button_tag "Delete Task", formaction: task_path(turbo_id_for(task)), formmethod: :delete, class: "mt-4 float-right p-2 rounded-md bg-red-300 hover:bg-red-400" %>
</fieldset>
<% end %>

1 comment on commit adfe726

@cjilbert504
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I like this bit task = Task.new(id: params[:id]) nor do I know if it's a good idea bc lol prob shouldn't be manually setting the id though maybe it's fine here bc it's just a fake task object in memory essentially.

Please sign in to comment.