logged_in?方法在PrescriptionsController中显示为undefined,但在UsersController中不显示。这真的很奇怪,因为它们都扩展了ApplicationController,其中存在logged_in_user方法。 logged_in?方法在SessionsHelper模块中。
this.setState({dob: Object.assign({}, this.state.dob, { year: '1980'} })
错误:
class PrescriptionsController < ApplicationController
before_action :logged_in_user, only: [:index] //this shows up as undefined
class UsersController < ApplicationController
before_action :logged_in_user, only: [:edit, :update, :index] //but this is ok
class ApplicationController < ActionController::Base
# Confirms a logged-in user.
def logged_in_user
unless logged_in?
flash[:danger] = "Please log in."
redirect_to login_url
end
end
module SessionsHelper
# Returns true if the user is logged in, false otherwise.
def logged_in?
!current_user.nil?
end
答案 0 :(得分:1)
在你的application.rb
里面放了这个
class ApplicationController
include SessionsHelper
end