0
您好我有軌一種形式,這是代碼Rails的複選框,獲得所選記錄JSON值
<%= form_tag getjson_products_path do %>
<% @products.each do |product| %>
<%= check_box_tag "product_ids[]",product.id , false%>
<%= product.name %>
<%= product.category %>
<%= product.price %>
<%= link_to 'Show', product %>
<%= link_to 'Edit', edit_product_path(product) %>
<%= link_to 'Destroy', product, method: :delete, data: { confirm: 'Are you sure?' } %>
<br>
<% end %>
<%= submit_tag "submit" %>
<br>
<% end %>
,我已經在產品控制器寫一個方法
def getjson
#stuff to do
redirect_to root_path
end
,這是我的路線文件
resources :products do
collection do
get 'getjson'
end
end
我想要的是獲得選定產品的json值,但每當我點擊提交它說路線呃請問我必須做什麼以及如何爲選定記錄獲取json值?