1

これはRailsチュートリアルブックからのものです:

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

そのため、このコードは、ユーザーがサインインしている場合にのみ投稿を作成および破棄できるようにしています。

Devise でこれを行うかどうか疑問に思っていましbefore_filter :authenticate_user!, only: [:create, :destroy]た。結果は同じ?

4

1 に答える 1

4

いいえ、同じではありません!使用する必要があります

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

あなたの場合。理解を深めるために、次のビデオをご覧ください。

アップデート:

以下は、devise wiki 記事の完全なリストです: https://github.com/plataformatec/devise/wiki/_pages

于 2012-10-31T12:54:02.633 に答える