私は以下のようにヘルパークラスを定義しました
module SessionsHelper
def current_user
@current_user= User.find_by_fbid(session[:fbid])
end
def sign_in(user)
session[:fbid] = user.fbid
@current_user = user
end
def signed_in?
!current_user.nil?
end
end
アプリケーションコントローラにヘルパークラスを含めました
class ApplicationController < ActionController::Base
protect_from_forgery
include SessionsHelper
end
サインインメソッドはセッションコントローラから呼び出されます
class SessionsController < ApplicationController
def create
user = User.find_or_create_by_fbid(params[:user][:fbid])
user.update_attributes(params[:user])
sign_in(user)
redirect_to user_path(user)
end
end
しかし、私はユーザー#showビューから 'current_user'変数にアクセスできません。
<% if signed_in? %>
<p>
<b>Current User:</b>
<%= current_user.name %>
</p>
<% end %>
それは言う:未定義のメソッド 'name' for nil:NilClass
誰でも助言してもらえますか? current_userメソッドは、インデックスからまったく呼び出されません。