私はここ数日、Rails を使い始めています。ユーザーが常にログインする必要があるフォームアプリケーションを作成しようとしています。
だから私はユーザー ログイン Railcast を作った: http://railscasts.com/episodes/250-authentication-from-scratch
ここで、他のコントローラーでログインを必須にする必要があるため、ユーザーはログインせずにアプリケーション全体にアクセスできません。次の方法を試しました。
application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
helper_method :current_user
private
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
def logged_in
return true if current_user
end
def login_required
if logged_in false
redirect_to log_in_path and return false
end
end
end
カテゴリ_コントローラー.rb
class CategoriesController < ApplicationController
before_filter :login_required
def new
def index
@categories = Categorie.all
end
このエラーが返されます:
CategoriesController#index の ArgumentError 引数の数が間違っています (0 に対して 1)
Extracted source (around line #14):
def logged_in
return true if current_user
end
私の before_filter :login_required には何か他のものが必要ですか? このエラーがよくわかりません。