我正在使用单元格4在rails 4中呈现登录表单, 我收到以下错误:
'undefined local variable or method `current_user' for <PopupLoginCell:0xbbd32e74>'
我尝试过包含include ApplicationHelper
。
请帮帮我。
#application_controller.rb
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
#protect_from_forgery
private
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
helper_method :current_user
end
# show.haml
- unless user_signed_in?
.popup-login
= form_for(@user, url:user_session_path) do |f|
%dl
%dt= f.label :email
%dd= f.email_field :email
%dt= f.label :password
%dd= f.password_field :password
= f.submit 'Login'
:javascript
$('.header__login-button a').click(function(){
$('.popup-login').css({ 'display' : 'block'});
});
#pop_up_login_cell.rb
class PopupLoginCell < Cell::ViewModel
# helper tự định nghĩa
include ApplicationHelper
def show
@user = User.new unless current_user.present?
render
end
end
答案 0 :(得分:1)
在您的单元格类中,您必须包含Devise帮助程序:
class PopupLoginCell < Cell::ViewModel
include Devise::Controllers::Helpers
helper_method :current_user
# Your class code
end
我希望它有所帮助。
答案 1 :(得分:0)