【问题标题】:ActionView::Template::Error (undefined method `email' for #<User id: nil, name: nil, created_at: nil, updated_at: nil>): on HerokuActionView::Template::Error (undefined method `email\' for #<User id: nil, name: nil, created_at: nil, updated_at: nil>): 在 Heroku
【发布时间】:2022-11-08 07:37:15
【问题描述】:

您好,感谢任何可以帮助我的人,我很绝望所以我不确定它是什么。在本地主机上一切正常。

我在 Heroku 中遇到了这个错误。

2022-10-28T02:39:55.334817+00:00 heroku[router]: ... ActionView::Template::Error (undefined method `email' for #\<User id: nil, name: nil, created_at: nil, updated_at: nil\>):
2022-10-28T02:40:20.465661+00:00 app\[web.1\]: \[0601e31b-0cf4-4714-a8ef-e41257302a21\]     11:
2022-10-28T02:40:20.465661+00:00 app\[web.1\]: \[0601e31b-0cf4-4714-a8ef-e41257302a21\]     12:   \<div class="field"\>
2022-10-28T02:40:20.465662+00:00 app\[web.1\]: \[0601e31b-0cf4-4714-a8ef-e41257302a21\]     13:     \<%= f.label :email %\>

2022-10-28T02:40:20.465662+00:00 app\[web.1\]: \[0601e31b-0cf4-4714-a8ef-e41257302a21\]     14:     \<%= f.email_field :email, autofocus: true, autocomplete: "email" %\>
2022-10-28T02:40:20.465663+00:00 app\[web.1\]: \[0601e31b-0cf4-4714-a8ef-e41257302a21\]     15:   \</div\>
2022-10-28T02:40:20.465663+00:00 app\[web.1\]: \[0601e31b-0cf4-4714-a8ef-e41257302a21\]     16:
2022-10-28T02:40:20.465663+00:00 app\[web.1\]: \[0601e31b-0cf4-4714-a8ef-e41257302a21\]     17:   \<div class="field"\>
2022-10-28T02:40:20.465664+00:00 app\[web.1\]: \[0601e31b-0cf4-4714-a8ef-e41257302a21\]  
2022-10-28T02:40:20.465664+00:00 app\[web.1\]: \[0601e31b-0cf4-4714-a8ef-e41257302a21\] app/views/devise/registrations/new.html.erb:14
2022-10-28T02:40:20.465664+00:00 app\[web.1\]: \[0601e31b-0cf4-4714-a8ef-e41257302a21\] app/views/devise/registrations/new.html.erb:3

问题似乎出在设备上,但我找不到在哪里

这是我的 aplication.html.erb 我认为问题可能出在哪里``

`

\<!DOCTYPE html\>
\<html\>
\<head\>
\<title\>BudgetApp\</title\>
\<%= csrf_meta_tags %\>

    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>

\</head\>

\<body\>

    <%= yield %>

\</body\>
\</html\>

`

这是问题似乎开始的设备的渲染

<h2 class="log-in-text"\>Log in User\</h2\>

\<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %\>
\<div class="field"\>
\<%= f.label :email %\>\<br /\>
\<%= f.email_field :email, autofocus: true, autocomplete: "email" %\>
\</div\>

\<div class="field"\>
\<%= f.label :password %\>\<br /\>
\<%= f.password_field :password, autocomplete: "current-password" %\>
\</div\>

\<% if devise_mapping.rememberable? %\>
\<div class="field"\>
\<%= f.check_box :remember_me %\>
\<%= f.label :remember_me %\>
\</div\>
\<% end %\>

\<div class="actions"\>
\<%= f.submit "Log in", :class =\> 'btn-form' %\>

\</div\>

\<% end %\>
\<div class="links-shared"\>
\<%= render "devise/shared/links" %\>
\</div\>

我会感谢帮助。 https://infinite-forest-50155.herokuapp.com 这是应用程序。 y 按注销按钮,但在日志中没有错误,但是当我单击登录或登录时出现相同的错误

我尝试在 stackoverflow 上查找相关问题,但任何错误似乎都与我的有关。 y 修改本地项目的环境以查看是否有效。我的本地项目运行良好,所以我不知道该怎么做。

【问题讨论】:

  • 您的用户模型是否有电子邮件字段?因为基本上这就是 Heroku 所抱怨的。

标签: ruby-on-rails devise


【解决方案1】:

问题是数据库迁移。我创建了创建用户数据库,然后从该数据库中删除了一个列,但是当我将迁移上传到 Heroku 时,它只迁移了创建而不是删除,因此导致数据库出现问题。

【讨论】:

  • 下次请注意写出问题详情。
猜你喜欢
  • 2015-05-28
  • 2018-03-13
  • 1970-01-01
  • 1970-01-01
  • 2013-07-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多