1

Row というモデルがあります。

# == Schema Information
#
# Table name: rows
#
#  id         :integer          not null, primary key
#  created_at :datetime
#  updated_at :datetime
#  numCols    :integer
#  type       :string(255)
#  content    :text
#  status     :string(255)
#  doc_id     :integer
#

class Row < ActiveRecord::Base
    belongs_to :doc, :foreign_key => "doc_id", :class_name => "Doc"

=begin
Status of a row can be:
1) header
2) body
3) ignore
=end

私のrows_controllerからのいくつかの関連するメソッドは次のとおりです:

 def update_multiple
    puts "update multiple"
    puts "#{row_params.inspect}"
    #How to use Update ALL
    #Row.update_all(row_params[:rows])
    redirect_to docs_path
  end

def row_params
      #params[:row]
        params.permit(:row, :rows =>[:id, :status, :content])
    end

フォームから update_multiple メソッドに送信される row_params は次のようになります。

   Parameters: {"utf8"=>"✓", "authenticity_token"=>"72nyykQ3uOL+VSicBk99HOtyCDpqDe4FaLzOa6EILYI=", "commit"=>"Update Row Classification", 
"rows"=>{"1"=>{"id"=>"1", "status"=>"ignore", "content"=>"[PROGRAMS] (All Locations|Consolidated),,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"}, 

"2"=>{"id"=>"2", "status"=>"header", "content"=>",,,,,,,,Stats >>,Rtg%,,,,,,,,,,,,,,,Shr% [Total TV Eng],,,,,,,,,,,,,,,#Stations,,,,,,,,,,,,,,"}, 

"3"=>{"id"=>"3", "status"=>"header", "content"=>"Areas,Program,Channel,Date,Weekday,Start time,End time,Duration,Episode Name,Ind.2+,A18+,A25-54,A18-49,A18-34,A55+,F25-54,F18-49,F18-34,M25-54,M18-49,M18-34,A12-34,T12-17,C2-11,Ind.2+,A18+,A25-54,A18-49,A18-34,A55+,F25-54,F18-49,F18-34,M25-54,M18-49,M18-34,A12-34,T12-17,C2-11,Ind.2+,A18+,A25-54,A18-49,A18-34,A55+,F25-54,F18-49,F18-34,M25-54,M18-49,M18-34,A12-34,T12-17,C2-11"},

....

上記の update_multiple メソッドで送信された値を使用して、params に含まれるすべての行を更新したい

どうすればいいですか?よくわかりません

どうもありがとうございました。

4

1 に答える 1