ruby-on-rails - nil:Nilclass 错误的未定义方法电子邮件
问题描述
我通过设计有用户。这就是我的用户模型。
我有家庭控制器
class HomeController < ApplicationController
before_action :authenticate_user!
def index
@users = User.all
end
def show
@user = User.find(params[:id])
end
end
我的登录没问题。我的索引页面工作正常。
我的显示页面显示登录用户的推文......
<h1>Profile Page for <%= @user.email %></h1>
<p><%= @user.email %></p>
<% @user.tweets.each do |tweet| %>
<p><%= tweet.content %></p>
<% end %>
当我尝试去 localhost:3000/users/1
undefined method `email' for nil:NilClass (error on first line)
我的路线
Rails.application.routes.draw do
get 'home/index'
get 'home/show'
devise_for :users
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
root to: 'home#index'
match 'users/:id' => 'home#show', via: :get
end
我该如何解决这个问题?
解决方案
推荐阅读
- c# - 将字符串 [] 转换为列表
在c#中 - regex - 用 ascii 连字符“-”替换所有连字符类型
- java - 声纳 - 实例化 SimpleDateFormat 对象时,指定区域设置
- python - 如何使用 python 和 PyCharm 生成和绘制三角波?我该如何编码?
- ios - swift 4迁移后的Xcode构建错误
- ruby - Ruby 将 .50 读取为 .5
- postgresql - 7 天退货/保留率
- linq - System.Data.EntityProxies group by 不断进行大量选择 GroupBy linq
- javascript - Javascript 日期:一场噩梦
- java - 如何读取文本文件、处理它并写入 toString()