Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails rails 5中的未知属性_Ruby On Rails_Excel_Import_Roo Gem - Fatal编程技术网

Ruby on rails rails 5中的未知属性

Ruby on rails rails 5中的未知属性,ruby-on-rails,excel,import,roo-gem,Ruby On Rails,Excel,Import,Roo Gem,嘿,我正试图将一个excel文件从我的工作表导入数据库,但我不知道有什么不起作用 获取未知属性: 我的床单是这样的: name title jalebi samosa s1 s2 s3 1 4 7 7 7 7 7 2 5 6 6 6 6 6 3 6 5 5 5 5 5 4 7

嘿,我正试图将一个excel文件从我的工作表导入数据库,但我不知道有什么不起作用 获取未知属性:

我的床单是这样的:

 name   title   jalebi  samosa  s1  s2  s3  
   1    4        7       7      7    7   7  
   2    5        6       6      6    6   6  
   3    6        5       5      5    5   5  
   4    7        4       4      4    4   4  
 {"name"=>1, "title"=>4, "jalebi"=>7, "samosa "=>9, "s1"=>7, "s2"=>7, "s3"=>7}
我的迁移是:

      class CreateTest3s < ActiveRecord::Migration[5.1]
    def change
      create_table :test3s do |t|
        t.string :name
        t.string :title
        t.string :jalebi
        t.string :samosa
        t.string :s1
        t.string :s2
        t.string :s3

        t.timestamps
      end
    end
  end
每当我尝试运行此操作时,都会出现以下错误:

 unknown attribute 'samosa ' for Test3.
散列值如下所示:

 name   title   jalebi  samosa  s1  s2  s3  
   1    4        7       7      7    7   7  
   2    5        6       6      6    6   6  
   3    6        5       5      5    5   5  
   4    7        4       4      4    4   4  
 {"name"=>1, "title"=>4, "jalebi"=>7, "samosa "=>9, "s1"=>7, "s2"=>7, "s3"=>7}

看起来您试图设置的属性是带有尾随空格的
“samosa”
。属性应该是不带空格的
“samosa”
。我猜您的电子表格标题就是空间的来源。

您能展示一下如何定义
Test3
模型吗?
import1
方法在哪个类中?哪一行代码生成了
未知属性
错误?这就是问题所在我发现了,除非看到哈希,否则我无法找到问题所在