Rails - 创建问题(活动记录)

时间:2016-05-12 04:12:23

标签: ruby-on-rails

我正在尝试使用Create方法在表中插入数据。但是我面临两个问题 -

  1. 其中一个时间戳列未出现在实际查询中。
  2. 我收到错误 - Encoding :: UndefinedConversionError(" \ xF0"从ASCII-8BIT到UTF-8):
  3. 从用户上传的文件中读取数据。

    我设置列值的逻辑是 -

    chat_date_time = date_sent + " " + time_sent
    data_array.push({:username => user,:chat_timestamp => chat_date_time ,:name => name,:sent_text => sent_text})
    $prev_date_time_sent = date_sent + " "+ time_sent
    $prev_name = name
    

    消息由Rails吐出 -

      

    (0.1ms)开始交易     SQL(0.4ms)INSERT INTO" chat_data_regulars" ("用户名","名称"," sent_text"," created_at"," updated_at")VALUES(?, ?,?,?,?)[["用户名"," 544cd2520b9b22a18fcedd34c544a8da"],["名称"," Tushar Saurabh"], [" sent_text","你给了你的被指导者批评性的反馈"],[" created_at"," 2016-05-12 03:47:35.018330& #34;],[" updated_at"," 2016-05-12 03:47:35.018330"]]      (13.6ms)提交事务      (0.2ms)开始交易      (0.1ms)回滚事务   14077ms完成500内部服务器错误(ActiveRecord:15.5ms)

    如果你看到,INSERT语句没有列chat_timestamp,即使我在代码中明确填充了值。 另外,我得到的错误是 -

    编码:: UndefinedConversionError(" \ xF0"从ASCII-8BIT到UTF-8):

    从一个文件读取数据,该文件具有UTF-8字符,但它正在读取的行没有。我使用sqlite作为db。

    以下是表格的架构 -

      

    创建表" chat_data_regulars" (" id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," username" varchar," chat_timestamp" datetime," name" varchar," sent_text" text," created_at" datetime NOT NULL," updated_at" datetime NOT NULL);

0 个答案:

没有答案