我如何访问用户详细信息?

How can i acces User details?

我想访问用户详细信息。 devise 已在用户注册时为其创建电子邮件和密码。例如,我现在想在我的视图中(在页面上)查看当前用户的地址。我的架构已添加到下面。我已经尝试过 <%= current_user.email %>,但没有用。

ActiveRecord::Schema.define(version: 2019_10_22_183225) do

  # These are extensions that must be enabled in order to support this database
  enable_extension "plpgsql"

  create_table "positions", force: :cascade do |t|
    t.string "tripnumber"
    t.string "activity"
    t.string "date"
    t.string "time"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

  create_table "users", force: :cascade do |t|
    t.string "email", default: "", null: false
    t.string "encrypted_password", default: "", null: false
    t.string "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.string "barge_name"
    t.index ["email"], name: "index_users_on_email", unique: true
    t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
  end

end

您的用户(User 的实例)应该可以通过 current_user 在控制器和他们的视图中访问,一旦您正确设置设计并让用户登录。如果 current_usernil表示用户还没有登录

Devise 在 warden 中间件之上工作,并依靠会话来验证用户身份,检查是否设置了 cookie。此外,如果您刚刚添加了设计 - 重新启动您的服务器,以便拾取中间件(并且 spring 通过 spring stop,只是为了确定)

似乎设计配置不正确。您应该重新检查 the guide line

在我的应用程序控制器和路由下方,通常当我打开 localhost:3000 它会显示 positions/new 页面,现在我被重定向到登录页面,这很好,但在登录后什么都不做....

class ApplicationController < ActionController::Base
  before_action :authenticate_user!
end

routes:
Rails.application.routes.draw do
  devise_for :users

  root to: 'positions#new'

resources :positions


end