Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.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
西纳特拉+;SQLite+;ActiveRecord(无法保存字符串)_Sqlite_Activerecord_Sinatra - Fatal编程技术网

西纳特拉+;SQLite+;ActiveRecord(无法保存字符串)

西纳特拉+;SQLite+;ActiveRecord(无法保存字符串),sqlite,activerecord,sinatra,Sqlite,Activerecord,Sinatra,我在数据库中保存字符串时遇到问题。整数进行得很顺利。我有一个模型付款,只有一个字段:command(String)。这是从控制台: p = Payment.new p.command = 'test' => "test" p.save => D, [2014-10-20T15:30:43.383504 #2229] DEBUG -- : (0.2ms) begin transaction => D, [2014-10-20T15:30:43.386985 #2229]

我在数据库中保存字符串时遇到问题。整数进行得很顺利。我有一个模型
付款
,只有一个字段:command(String)。这是从控制台:

p = Payment.new
p.command = 'test'
=> "test" 
p.save
=> D, [2014-10-20T15:30:43.383504 #2229] DEBUG -- :    (0.2ms)  begin transaction
=> D, [2014-10-20T15:30:43.386985 #2229] DEBUG -- :    (0.1ms)  commit transaction
=> true 
Payment.last
=> #<Payment id: 1, command: nil> 

有趣的时刻:如果我在模式中将字符串更改为整数->则保存整数值时不会出现任何问题

从模型中删除属性访问器。在
ActiveRecord
模型的情况下,
ActiveRecord
已经为您的数据列生成了getter和setter<不需要代码>属性访问器
attr\u访问器
-是一种在
ActiveRecord
模型中控制批量分配的不推荐方法。

从模型中删除
attr\u访问器
。在
ActiveRecord
模型的情况下,
ActiveRecord
已经为您的数据列生成了getter和setter<不需要代码>属性访问器
attr_accessor
-是一种在
ActiveRecord
模型中控制批量分配的不推荐方法。谢谢,问题很简单!请把你的评论作为答案,这样我才能把它标记为正确。
require 'sinatra'
require 'activerecord'
require 'sinatra/activerecord'

set :database, 'sqlite3:qiwi_exline_development.sqlite3'

get '/' do
  @payments = Payment.all
  haml :index
end

class Payment < ActiveRecord::Base
  include ActiveModel::Model

  attr_accessor :command
end
ActiveRecord::Schema.define(version: 20141020092721) do

  create_table "payments", force: true do |t|
    t.string "command"
  end

end