ruby on rails - Controller method not working: how to find related record in related model? -
i have member model related organization model: 1 organization has many members. in controller method below try find organization in line 3 set status activated in line .
however, when running tests error message nomethoderror: undefined method 'organization_id' nil:nilclass
. don't think though member nil. ideas causing this?
def edit member = member.find_by(email: params[:email]) organization = organization.find_by(params[:member.organization_id]) if member && !member.activated? && member.authenticated?(:activation, params[:id]) member.activate log_in("member", member) flash[:success] = "account activated! can update profile." redirect_to member organization.update_attributes(activated: true) unless organization.activated? elsif user && !user.activated? && user.authenticated?(:activation, params[:id]) user.activate log_in("user", user) flash[:success] = "account activated! can update profile." redirect_to user else flash[:danger] = "invalid activation link" redirect_to root_url end end
member = member.find_by(email: params[:email]) organization = organization.find_by(params[:member.organization_id])
you have member
, activerecord::associations
magic:
member = member.find_by(email: params[:email]) if member organization = member.organization else #whatever end
Comments
Post a Comment