使用类似于我用于删除标签的成员路线:
resources 'factory' do
resources 'tags' do
member do
delete :remove
end
end
resources 'project_files' do
member do
delete :remove
end
end
end
我(应该)在项目控制器中调用:
class ProjectFilesController < ApplicationController
def remove
@factory = Factory.find(params[:fabmoment_id])
@project_file = ProjectFile.find(params[:id])
authorize @factory, :project_file?
@project_file.remove!
head :ok
end
end
我无法检查其中的正确性。部分_project_files看起来像:
<li class="project_file">
<% if policy(factory).project_file? %>
<%= link_to "<span></span>".html_safe,
remove_factory_project_file_path(factory, project_file), method: :delete, remote: true,
class: "remove",
title: "remove" %>
<% end %>
<%= link_to File.basename(project_file.url), project_file.url %>
(<%= number_to_human_size(project_file.file.size) %>)
</li>
通过在factory#show
视图中使用render方法传递locales来调用它。 (也可以添加索引。)
像这样,它大多等于标签删除动作,我喜欢保持事情的结果和简单。
我从规范中收到的错误:
没有路线匹配[DELETE]&#34; /factories/1/project_files/%2Fuploads%2Ffactory%2Fproject_files%2F1%2Fthe_puritan_1st_floor.stl/remove"
我的工厂型号仅包含mount_uploaders :project_files, ProjectFileUploader
关于如何使这项工作的任何想法?