2017-09-26 7 views
1


私はRuby on Railsをで(製品を無効にすることができます)を有効に一部とのトラブル、私の方法を抱えているに返します。 ユーザがenable = trueを設定したい製品を選択するように、いくつかのチェックボックスを作成しました。submit_tagとcheck_box_tagエラー

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テーブルと がエラーを返すキープ私の方法enable

" 'ID' との製品が見つかりませんでした=有効" 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 %> 

助けてくれてありがとう!

+0

チェック。私はそれが製品/有効な権利だと思いますか? – krishnar

+0

あなたのレールの一部を表示する(log/development.log)。 –

答えて

0

使用whereは、選択した製品を見つけるために、それらを更新するとき:コンソールに当たっているものをURL

Product.where(id: params[:selected_products]).update_all(enable: true)

関連する問題