Rails - 如何在View文件中显示设计Users表中的数据?

问题描述:

我试图在登录时向用户显示一个简单的欢迎消息,例如“Welcome,Anthony!”。Rails - 如何在View文件中显示设计Users表中的数据?

我创建FIRST_NAME,并在登录了姓氏的属性,并将其迁移到色器件用户表,并允许通过ApplicationController中新的属性与此代码,

class ApplicationController < ActionController::Base 
    protect_from_forgery with: :exception 

    before_action :configure_permitted_parameters, if: :devise_controller? 

    protected 

    def configure_permitted_parameters 
    devise_parameter_sanitizer.permit(:sign_up, keys: [:username, :first_name, :last_name]) 
    end 


end 

这工作完全正常,但是,我想在我的导航栏中的application.html.erb文件中显示first_name,该文件在用户登录后充当欢迎消息。

如何显示来自Devise Users表的信息?

谢谢,

蚂蚁。

(如果我需要增加任何功能,然后才让我知道!)

一旦你登录,你应该能够访问CURRENT_USER对象,从中可以得到FIRST_NAME和显示应用程序布局中的欢迎消息。

+0

谢谢! current_user是我所缺少的。我新来的铁轨!这是我的解决方案,

  • 欢迎,
  • AntChamberlin