Skip to content

Commit

Permalink
make Source CRUD go Turbo
Browse files Browse the repository at this point in the history
  • Loading branch information
pessi-v committed Jul 4, 2024
1 parent 8f2339c commit ec39d2b
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 14 deletions.
2 changes: 2 additions & 0 deletions app/controllers/sources_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def create
if @source.save
format.html { redirect_to source_url(@source), notice: "Source was successfully created." }
format.json { render :show, status: :created, location: @source }
format.turbo_stream
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @source.errors, status: :unprocessable_entity }
Expand Down Expand Up @@ -71,6 +72,7 @@ def destroy
respond_to do |format|
format.html { redirect_to sources_url, notice: "Source was successfully destroyed." }
format.json { head :no_content }
format.turbo_stream
end
end

Expand Down
5 changes: 4 additions & 1 deletion app/views/sources/_source.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ css:
}


.source_info id=dom_id(source)
= turbo_frame_tag source
p
strong
'Name:
Expand All @@ -30,3 +30,6 @@ css:
'Last error status:
p.error
= source.last_error_status

= button_to "Edit", edit_source_path(source), method: :get
= button_to "Delete", source, method: :delete, form: {data: {turbo_confirm: "Deleting this source will destroy all of it's articles too. If you want to keep the articles, you should just deactivate the source."}}
2 changes: 2 additions & 0 deletions app/views/sources/create.turbo_stream.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
= turbo_stream.prepend "sources", partial: "sources/source", locals: { source: @source }
= turbo_stream.update Source.new, ""
1 change: 1 addition & 0 deletions app/views/sources/destroy.turbo_stream.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
= turbo_stream.remove @source
10 changes: 0 additions & 10 deletions app/views/sources/edit.html.erb

This file was deleted.

12 changes: 12 additions & 0 deletions app/views/sources/edit.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

h1
= 'Editing source'

= turbo_frame_tag @source do
= render "form", source: @source

br

div
= link_to "Show this source", @source
= link_to "Back to sources", sources_path
8 changes: 5 additions & 3 deletions app/views/sources/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

.list_view_desktop
= turbo_frame_tag 'new_source'
- @sources.each do |source|
= link_to(source) do
= render source
= turbo_frame_tag 'sources'
= render @sources
/ - @sources.each do |source|
/ = link_to(source) do
/ = render source

0 comments on commit ec39d2b

Please sign in to comment.