在rails中调用应用程序控制器中的当前用户
嗨,大家好,我对rails非常陌生,如果我的问题很简单或愚蠢,请理解我。 我目前正在使用devise
gem,我试图将modal放在我的application.html.erb
以便模式总是出现在顶部,但我得到的错误信息是,
undefined局部变量或方法`current_user’for ApplicationController:Class
我应该在哪里修复从Application.html.erb
的Post.rb
调用记录? 感谢您的帮助!
Application.html.erb
应用控制器
class ApplicationController < ActionController::Base before_action :configure_permitted_parameters, if: :devise_controller? protected @post_list = Post.where(user_id: current_user).list? def configure_permitted_parameters devise_parameter_sanitizer.permit(:sign_up, keys: [:name]) devise_parameter_sanitizer.permit(:account_update, keys: [:name]) end end
这是您可以访问ApplicationController
current_user
class ApplicationController < ActionController::Base protect_from_forgery with: :exception def current_user_posts? @post_list = Post.where(user_id: current_user).list? // current_user should work here. end end