4

我正在使用roo-rb/roo将数据的 csv 文件导入我的数据库。但是有 55 行 4 列,我收到了 ActionDispatch::Cookies::CookieOverflow 错误。任何人都知道可能是什么原因造成的,或者是什么试图创建这个我猜是最大化的 cookie?

这是我的导入功能:

  def self.import(file)
    result = {
        errors: 0,
        success: 0,
        row_results: { }
    }

    spreadsheet = open_spreadsheet(file)
    header = spreadsheet.row(1)

    transaction do
      (2..spreadsheet.last_row).each do |i|
        row = Hash[[header, spreadsheet.row(i)].transpose]

        file_row_hash = row.to_hash
        first_name = file_row_hash['first_name']
        last_name = file_row_hash['last_name']
        company_name = file_row_hash['company_name']
        email = file_row_hash['email']
        company = Company.new(:name => company_name)

        if company.save
          password = Devise.friendly_token.first(8)
          user = StaffMember.new({ :email => email, :encrypted_password => password, :first_name => first_name, :last_name => last_name, :company_id => company.id })

          if user.save
            result[:success] += 1
            result[:row_results][i] = "row #{i}: #{company['name']} and #{company['first_name']} + #{company['last_name']} was successfully created"
          else
            result[:errors] += 1
            result[:row_results][i] = "row #{i}: #{company['name']} saved BUT staff_member #{company['first_name']} + #{company['last_name']} failed to save"
          end
        else
          result[:errors] += 1
          result[:row_results][i] = "row #{i}: #{company['name']} and #{company['first_name']} + #{company['last_name']} failed to be created."
        end
      end
    end
    return result
  end
4

1 回答 1

0

您可以通过更改 cookie 的存储方式来解决此问题。

config/initializers/session_store.rb

你应该有类似的东西:

Rails.application.config.session_store :cookie_store, key: 'YOUR_KEY'

只需更改:cookie:store:active_record_store这样:

Rails.application.config.session_store :active_record_store, :key => 'YOUR_KEY'
于 2016-03-31T15:16:53.800 回答