2

我成功地設置了decent_exposure gem,因爲這個railscastRails 3使用current_user和decent_exposure訪問範圍

我想使用範圍訪問與current_user編輯/更新/創建操作,以避免通過比較對象的所有者與current_user檢查權限。

控制器:

class CommentsController < ApplicationController 
expose(:article) 
expose(:comments) { article.comments } 
expose(:comment) 

def index 
end 

def new 
end 

def create 
    if comment.save 
    redirect_to comment.article, :notice => "Successfully created comment!" 
    else 
    render :new 
    end 
end 
end 

我怎麼能有decent_exposure這樣的事情在我的編輯操作,例如:

@comment = current_user.comments.find(params[:id]) 

提前感謝!

回答

1

我認爲你可以這樣做:

暴露(:user_comments){} current_user.comments

暴露(:USER_COMMENT)

的USER_COMMENT應該先限定current_user.comments,你會使用user_comment將在您的視圖中使用。