作为一个学校项目,我应该创建一个任务管理器应用程序。我到了那里,但我似乎无法弄清楚的一件事是: 我有3个模型:任务,类别和标签。一项任务只有一个类别,但有很多标签。我们应该能够按类别过滤任务,这样,当您选择类别时,您将被重定向到/ tasks / by-category / category_id。 By_category没有模型,只有task文件夹中的视图。
我的路线:
resources :tasks do
collection do
get 'net_connection',action: :net_connection
get 'completed'
get 'pending'
get 'by-category',action: :by_category,:as => :by_category
get 'search'
delete 'destroy_multiple'
end
member do
delete 'delete'
end
index.html.erb在任务中:
<div>
<%= simple_form_for :by_category,url: by_category_tasks_path,method: :get do |f| %>
<%= f.input :category,collection: Category.all,label_method: :title,value_method: :id,label: "Category",include_blank: true %>
<%= f.submit "Filter by category" %>
<%end%>
</div>
任务控制器:
def by_category
end
如何将类别ID提交到按类别的URL?