0

セル 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
4

2 に答える 2