2011-01-22 3 views
11

Sto utilizzando devise per l'autenticazione, tuttavia non riesco a vedere e il filtro azione per specificare le azioni che richiedono l'accesso dell'utente, è incluso nella gemma del progetto? se non come potrei crearne uno, ho un'idea, ma visto che sono nuovo alle rotaie preferisco vedere prima una soluzione da un programmatore più esperto.Devisionare il filtro di azione per le azioni che richiedono l'autenticazione

risposta

23

Vedere 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

L'altra soluzione è quella di utilizzare, ad esempio: ad eccezione => login, il suo utilizzo quando l'intero autenticazione utilizzo app e si desidera avere una pagina con accesso pubblico