wyc
wyc

Reputation: 55293

Is Devise's :authenticate_user! the same as :signed_in_user?

This is from the Rails Tutorial Book:

http://ruby.railstutorial.org/

  before_filter :signed_in_user, only: [:create, :destroy]


  def signed_in_user
    unless signed_in?
      store_location
      redirect_to signin_url, notice: "Please sign in."
    end
  end

  def signed_in?
    !current_user.nil?
  end

So the code is letting users create and destroy posts only if they are signed in.

I was wondering if doing this with Devise before_filter :authenticate_user!, only: [:create, :destroy]. Results in the same thing?

Upvotes: 1

Views: 3365

Answers (1)

Pavel Nikolov
Pavel Nikolov

Reputation: 9541

No it is not the same! You must use

before_filter :authenticate_user!, only: [:create, :destroy

in your case. Watch these videos for better understanding:

UPDATE:

Here is a complete list of devise wiki articles: https://github.com/plataformatec/devise/wiki/_pages

Upvotes: 4

Related Questions