前提・実現したいこと
Rails初心者です。
ユーザー登録の時Active Storageで画像登録のバリデーションを、has_one_attachedの記述でしたいのですが、何か方法がわかる方いらっしゃいますでしょうか。
発生している問題・エラーメッセージ
Active Storageで一つだけファイルを添付したい時のバリデーションが組めない
該当のソースコード
models/user.rb
class User < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable validates :email, presence: true validates :name, presence: true validates :profile, presence: true validates :avatar, presence: true has_one_attached :avatar has_many :tweets has_many :comments acts_as_followable # フォロワー機能 acts_as_follower # フォロー機能 has_many :messages, dependent: :destroy has_many :entries, dependent: :destroy end
試したこと
has_maany_attachedでは、validates:avatar presence:trueで成功します。
補足情報(FW/ツールのバージョンなど)
Ruby version 2.5.1
Rails version 5.2.3
あなたの回答
tips
プレビュー