2
프로필을 작성하지 않은 사용자가 편집 페이지로 리디렉션되도록하려고합니다.ROR 모델의 다른 테이블에서 변수 가져 오기
두 개의 테이블, 즉 사용자 (Devise 핸들)와 프로필이 있습니다.
프로필 내가 profiles_complete의 부울을 취하고 다시 전달하는 방법이라고 profile_complete를 정의하려고 내 사용자 모델에서 profile_complete
라는 행이 있습니다.
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
has_many :profiles, :dependent => :destroy
def profile_complete?
self.profile.profile_complete == true
end
end
그러나 profile_complete 메소드의 행이 무엇인지 알 수없는 것 같습니다. 올바른 위치에서 다른 비트가 작동하고 있지만이 변수는 아무 도움이되지 않습니까? 건배 :
사실상 * 모든 인스턴스에서 '사실'과 무언가를 비교하는 것은 무의미합니다. 당신은 그걸 그대로 돌려 주어야합니다. – tadman
사용자에게'has_one : profile'을 주시겠습니까? 그러면 할 수 있어야합니다 'profile &&profile.profile_complete' – bullfrog
많은 프로필을 가질 수 있습니다. @ bullfrog –