2011-01-22 10 views
11

私は認証にdeviseを使用していますが、ユーザーにログインする必要のあるアクションを指定するためのアクションフィルタは表示されません。これはdevise gemに含まれていますか?どうすればいいか分からないけど、アイデアはあるけど、レールが初めてだから、経験豊富なプログラマーの方が最初に解決策を見たいと思う。認証が必要なアクションのアクションフィルタを作成する

答えて

23

Devise Readmeを参照してください。

class PostsController < ApplicationController 
    respond_to :html 

    # Tell Devise that the #destroy action is 
    # special, and that the user must be 
    # authenticated in order to access the 
    # #desroy action. 
    # Note that the name of the method here, 
    # #authenticate_user!, depends on the 
    # particular class/table that you have 
    # set up to be managed with Devise. 
    before_filter :authenticate_user!, 
    :only => [:destroy] 

    before_filter :find_post!, 
    :only => [:destroy] 

    def destroy 
    @post.destroy 
    respond_with @post 
    end 

    private 

    def find_post! 
    @post = Post.find(params[:id]) 
    end 
end 
0

他の解決策は、例えば使用することです:=>ログインを除いて、その時にアプリケーション全体の利用認証を使用して、パブリックアクセス

でページを持ちたいです
関連する問題