1
我在Ruby on Rails中一些麻烦和我的方法使(产品可以被禁用)。 我创建了一些复选框,以便用户选择他想要设置的产品enable = true。 保持返回错误 “无法与 'ID' 发现产品= ENABLE”submit_tag与check_box_tag返回错误
我的方法enable
:
def enable
Product.update_all(["enable=?", true], :id => params[:selected_products])
redirect_to root_url
end
我routes.rb
:
Rails.application.routes.draw do
get 'product_export/new'
get 'product_imports/new'
resources :users
resources :product_imports
resources :products do
collection do
post :import
post :export
post :enable
end
end
root to: 'products#index'
end
,最后我view
与表e check_box_tag:
<%= form_tag enable_products_path, :method => :put do %>
<%= submit_tag "Enable products" %>
<table class="table table-striped table-responsive" id="productsTable">
<thead class="thead-inverse">
<tr>
<th/>
<th>Code</th>
<th>Enable</th>
<th>Bar code</th>
<th>Unit cost</th>
<th>Description</th>
<th>Family</th>
<th>Final</th>
<th>Measure</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @products.each do |product| %>
<tr>
<td><%= check_box_tag 'selected_products[]', product.id %></td>
<td><%= link_to (product.code), edit_product_path(product) %></td>
<td><%= product.enable %></td>
<td><%= product.bar_code %></td>
<td><%= product.unit_cost %></td>
<td><%= product.description %></td>
<td><%= product.family %></td>
<td><%= product.final %></td>
<td><%= product.measure %></td>
<td><%= link_to 'Destroy', product, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
感谢您的帮助!
检查什么URL在控制台打。我认为这是产品/启用权? – krishnar
显示此操作的一部分rails日志(log/development.log)。 –