UPDATE学习导轨 - 上删除
我已经延长我的应用程序有一个名为“标记”(非常类似的设置,如在博客评论)新模式后,改写路由错误。
预期结果:用户在点击link_to按钮删除标签时停留在页面上;我现在得到一个路由错误(下面),我不明白为什么。
没有路由匹配[删除] “/注释/ 7 /标签”
标签列表中添加到视图的注解是这样的:
<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 do |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>
这些都是我的路线:
Rails.application.routes.draw do
root 'dashboard#index'
devise_for :users
resources :users, :documenttypes, :tagtypes
resources :documents do
resources :tags
get "pdf", on: :member
end
resources :annotations do
resources :comments, :tags
get "pdf", on: :member
end
get "annotations/:id/annotate" => "annotations#annotate", as: 'annotate'
get "angular_test", to: "angular_test#index"
mount PdfjsViewer::Rails::Engine => "/pdfjs", as: 'pdfs'
而且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 表视图始终有一个空行,这是我无法删除。然后我得到路由错误。使用添加标签时创建的行,这不会发生,我可以删除它们。为什么我得到一个空行?
是的,你可以在没有Jquery的情况下使用普通的javascript。 –
没有普通的JS,只使用rails/ruby/erb? –
是的,页面重新加载。 –