当我尝试在控制台中创建新录制时,我收到此错误:
TypeError: can't cast Strongbox::Lock to binary
但是,我使用Strongbox的其他表格工作正常。 我的架构如下所示:
create_table "recordings", force: true do |t|
t.datetime "date"
t.string "position"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "patient_id"
t.binary "sound_file"
t.binary "sound_file_key"
t.binary "sound_file_iv"
t.binary "image_file"
t.binary "image_file_key"
t.binary "image_file_iv"
t.binary "audio_data_points"
t.binary "audio_data_points_key"
t.binary "audio_data_points_iv"
end
create_table "notes", force: true do |t|
t.integer "user_id"
t.integer "recording_id"
t.integer "patient_id"
t.binary "content"
t.binary "content_key"
t.binary "content_iv"
end
我的模特看起来像这样:
class Note < ActiveRecord::Base
validates :content, presence: true
belongs_to :user
belongs_to :recording
belongs_to :patient
encrypt_with_public_key :content,
:key_pair => Rails.root.join('config','keypair.pem')
end
class Recording < ActiveRecord::Base
validates :date , presence: true
validates :position , presence: true
validates :sound_file , presence: true , uniqueness: true
validates :image_file , presence: true , uniqueness: true
has_many :notes, dependent: :destroy
has_many :srecordings
has_many :users, through: :srecordings
belongs_to :patient
encrypt_with_public_key :sound_file, :image_file, :audio_data_points,
:key_pair => Rails.root.join('config','keypair.pem')
end
我之前从未使用过Strongbox,但它在其他任何地方都能正常工作,所以我不太理解这个。想法?
答案 0 :(得分:1)
对于唯一性的验证不适用于strongbox。您的录制模型是唯一检查sound_file和image_file唯一性的模型。最好的方法是添加自定义验证以检查此处的唯一性。令人惊讶的是,我用同样的模型想出了这个:)
P.S。我现在正在实现自定义验证以获得唯一性。