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

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -