2011-10-03 9 views
0

나는 비계 + 집 "을 만들었습니다. 나는 사용자가 자신의 집만 편집 할 수 있기를 원합니다.사용자 정의 current_user devise + Mongoid

이 내 houses_controller입니다 : 내가 최고 houses_controller 너무이 코드가

def authenticate_owner! 
    @house = house.find(params[:id]) 
    if user_signed_in? && current_user.email == @house.user.email 
     return true 
    end 
    redirect_to root_path, :notice => "You must have permission to access this category." 
     return false 
    end 

:

"

before_filter :authenticate_owner! 
skip_before_filter :authenticate_owner! , :only => [:show, :index, :new] 

하지만 작동하지를 항상 메시지를 표시 이 카테고리에 액세스 할 수있는 권한이 있어야합니다. "

발판을 만든 사용자를 어떻게 얻을 수 있으며 등록 된 사용자와 비교할 수 있습니까?

def authenticate_owner! 
    @house = house.find(params[:id]) 
    if user_signed_in? && current_user.email == @house.user.email 
     return true 
    else 
     redirect_to root_path, :notice => "You must have permission to access this category." 
     return false # this will never be executed!! 
    end 
end 
+0

게시 한 코드가 완전하지 않습니다. – Tilo

답변

0

고정 : D 문제는 @house = .find (PARAMS [: 아이디])

1

당신이 쓰는 당신은 아마 의미 .. 거기에 다른 사람을 둘 필요가있다 : @house = .find (params [: id])

관련 문제