私はレールにかなり慣れていないため、いくつかの概念はまだ混乱しているため、モデルを作成して外部キーを定義し、いくつかのフィールドを空白にしないなどの簡単なものをバリデーターにも定義しました。例えば:
class KeyPerformanceInd < ActiveRecord::Base
#attr_accessible :name, :organization_id, :target
include ActiveModel::ForbiddenAttributesProtection
belongs_to :organization
has_many :key_performance_intervals, :foreign_key => 'kpi_id'
validates :name, presence: true
validates :target, presence: true
validates :organization_id, presence: true
end
それから頭に浮かんだ質問は、うーん、このモデルに、foreign_key として使用している他のテーブルのキーも存在し、有効かどうかを確認するバリデーターのいくつかを書くべきかということでした。
それとも、RSpec テストで行うことですか? モデルではありませんか?