Rails - routing error on delete -
update rephrased after learning
i have extended app new model called 'tag' (very similar set comments in blog).
intended outcome: user stay on page when clicking link_to button delete tag; routing error (below) , don't understand why.
no route matches [delete] "/annotations/7/tags"
the tag list added view annotations this:
<div class="panel panel-default" style="background-color: white; word-wrap: break-word; font-size: 0.9em;"> <table id="tags" class="table table-hover"> <thead> <tr> <th>tag</th> <th>type</th> <th></th> </tr> </thead> <tbody> <% @annotation.tags.each |tag| %> <tr> <td><%= tag.content %></td> <td><%#= tag.tagtype_id | tag.tagtype.typeoftag %></td> <td><%= link_to '', [tag.annotation, tag], method: :delete, data: { confirm: 'please confirm deletion!' }, :class => "glyphicon glyphicon-remove" %></td> </tr> <% end -%> </tbody> </table> </div>
these routes:
rails.application.routes.draw root 'dashboard#index' devise_for :users resources :users, :documenttypes, :tagtypes resources :documents resources :tags "pdf", on: :member end resources :annotations resources :comments, :tags "pdf", on: :member end "annotations/:id/annotate" => "annotations#annotate", as: 'annotate' "angular_test", to: "angular_test#index" mount pdfjsviewer::rails::engine => "/pdfjs", as: 'pdfs'
and tags.controller
class tagscontroller < applicationcontroller def create @annotation = annotation.find(params[:annotation_id]) @comment = @annotation.tags.create(tag_params) redirect_to annotation_path(@annotation) end def destroy @annotation = annotation.find(params[:annotation_id]) @comment = @annotation.tags.find(params[:id]) @comment.destroy redirect_to annotate_path(@annotation) end private def tag_params params.require(:tag).permit(:content, :location, :tagtype_id) end end
update table in view has empty row, cannot delete. routing error. rows created when adding tag, not happen , can delete them. why getting empty row?
this needs done using ajax (asynchronously), need have destroy action respond javascript. can adding remote option link deletion below:
<td><%= link_to 'delete', [tag.annotation, tag], method: :delete, remote: true, data: { confirm: 'please confirm deletion!' }, :class => "glyphicon glyphicon-remove" %></td>
the remote: true
option makes request ajax. on controller side need respond resulting javascript code want execute, hiding row want delete.
in views folder, under tags controller need create file called destroy.js , in file specify code want executed handling hide example row.
Comments
Post a Comment