File tree Expand file tree Collapse file tree 2 files changed +16
-5
lines changed
Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -7,16 +7,19 @@ class SnippetsController < ApplicationController
77
88 def index
99 @display_popover = true
10- @snippets = current_user . filed_snippets
10+ @snippets = current_user . filed_snippets . includes ( :user )
1111
12+ # TODO: Extract this logic to model/service
1213 @snippets = @snippets . where ( 'description ILIKE ?' , "%#{ params [ :search ] } %" ) if params [ :search ]
1314
1415 @snippets = @snippets
1516 . order ( created_at : :desc )
1617 . paginate ( page : params [ :page ] || 1 , per_page : 6 )
1718
1819 respond_to do |format |
19- format . html
20+ format . html do
21+ flash [ :notice ] = params [ :notice ] if params [ :notice ]
22+ end
2023 format . json do
2124 render json : {
2225 entries : render_to_string ( partial : 'snippets/snippets' , formats : [ :html ] ) ,
Original file line number Diff line number Diff line change @@ -25,9 +25,13 @@ export default class extends Controller {
2525
2626 axios . delete ( this . confirmPath , { headers : { 'accept' : 'application/json' } } )
2727 . then ( res => {
28- document . getElementById ( this . resourceId ) . remove ( )
29- this . alertTarget . remove ( )
30- this . toast . display ( 'Snippet deleted!' )
28+ if ( this . listItem ) {
29+ this . listItem . remove ( )
30+ this . alertTarget . remove ( )
31+ this . toast . display ( 'Snippet deleted!' )
32+ } else {
33+ window . location . href = '/snippets?notice=Snippet%20deleted!'
34+ }
3135 } )
3236 . catch ( error => {
3337 console . error ( error )
@@ -47,6 +51,10 @@ export default class extends Controller {
4751 return this . data . get ( 'resourceId' )
4852 }
4953
54+ get listItem ( ) {
55+ return document . getElementById ( this . resourceId )
56+ }
57+
5058 get app ( ) {
5159 return document . getElementById ( 'vue-app' )
5260 }
You can’t perform that action at this time.
0 commit comments