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? –
是的,頁面重新加載。 –