我想在下表中放置一些模型级别的验证:
create_table :audios do |t|
t.integer :library_id, :null => false
t.string :file, :null => false, :limit => 2048
t.string :name, :limit => 512
t.timestamps
end
这是否意味着,我的模型(到目前为止)看起来像:
class Audio < ActiveRecord::Base
belongs_to :library
end
拥有
class Audio < ActiveRecord::Base
validates_presence_of :library
...
或者
class Audio < ActiveRecord::Base
validates_presence_of :library_id
...
?