2011-01-22 20 views
11

Kimlik doğrulama için kullanıyorum ancak kullanıcının oturum açmasını gerektiren eylemleri belirtmek için eylem filtresini göremiyorum, bu düzenleme gemide yer alıyor mu? değilse nasıl bir tane oluşturabilirim, bir fikrim var ama raylara yeniyken, daha deneyimli bir programcıdan bir çözüm bulmayı tercih ederim.Kimlik doğrulama gerektiren eylemler için eylem filtresi ayırma

cevap

23

Devise Readme'a bakın.

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

diğer çözüm, örneğin kullanmaktır: onun zaman tüm uygulama kullanımı kimlik doğrulaması kullanarak => giriş hariç ve kamu erişimi olan bir sayfa olmasını istiyorsanız