私はそのモデルを持ってListingいbelongs_to :userます。または、User has_many :listings. 各リストには、それを分類するカテゴリ フィールドがあります (犬、猫など)。にはUser、 と呼ばれるブール フィールドもありますis_premium。
カテゴリを検証する方法は次のとおりです...
validates_format_of :category,
:with => /(dogs|cats|birds|tigers|lions|rhinos)/,
:message => 'is incorrect'
プレミアム ユーザーのみがtigers、lions、およびrhinosを追加できるようにしたいとしましょう。これについてどうすればいいですか?before_saveメソッドでそれを行うのが最善でしょうか?
before_save :premium_check
def premium_check
# Some type of logic here to see if category is tiger, lion, or rhino.
# If it is, then check if the user is premium. If it's not, it doesn't matter.
# If user isn't premium then add an error message.
end
前もって感謝します!