ruby on rails - Devise rubygem - How do you filter actions for authenticated/non-authenticated users? -
i new rails , need create simple rails project these conditions:
- there must page articles (title + body)
- anyone can read articles
- only authenticated users can create/edit/delete articles
i used scaffold generate controller articles , gem devise create authentication system. dont know how implement necessary conditions.
thanks reply.
if user model called user
, include following in controller:
before_filter :authenticate_user!
if not called user
, replace word user in authenticate_user
whatever is.
you add directly under controller declaration, so:
class articlescontroller < applicationcontroller before_filter :authenticate_user! #rest of code end
if want restrict actions in controller logged in users, can use except
exclude actions. here, index , show can seen anyone:
before_filter :authenticate_user!, :except => [:index, :show]
or only
include specific actions. here, authenticated users can listed actions:
before_filter :authenticate_user!, :only => [:new, :edit, :create, :update, :delete]
Comments
Post a Comment