2011-10-03 94 views
0

我有設計+創建一個腳手架「房子」,我希望用戶只能編輯自己的房子。自定義current_user設計+ Mongoid

這是我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 

我有太多的代碼在頂部houses_controller:

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

,但沒有工作,總是顯示消息:

「您必須具有訪問此類別的權限。「

我如何獲得創建腳手架的用戶並將其與註冊的用戶進行比較?

+0

您發佈的代碼不完整 – Tilo

回答

0

修正:d的問題是@house = 房子 .find(PARAMS [:編號]),是: @house = House .find(params [:id])

1

你需要把別人那裏..你大概的意思是寫:

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