【问题标题】:Local works, on Heroku ActionView::Template::Error本地作品,在 Heroku ActionView::Template::Error 上
【发布时间】:2014-09-01 22:29:00
【问题描述】:

我使用 Rails 4 和 Devise gem 进行授权。 我在名为“用户名”的设备的注册表单中添加了附加字段 在这里:

enter code here
<div><%= f.label :username %><br />
<%= f.text_field :username, autofocus: true %></div>

我是这样做的:https://stackoverflow.com/a/20667360/3826643

本地它工作正常。我可以注册,然后在我的用户面板中,我可以看到在注册表单中输入的用户名。

在 heroku 上,当我点击“注册”时,我会给出“我们很抱歉,但出了点问题。”

Heroku 在此处记录:

2014-07-11T10:02:24.514630+00:00 heroku[router]: at=info method=GET path="/users/sign_up" host=test-app12.herokuapp.com request_id=32d968fd-2154-4a02-ba8a-878bb7f85a02 fwd="78.8.153.110" dyno=web.1 connect=5 service=378 status=500 bytes=857
2014-07-11T10:02:24.509598+00:00 app[web.1]:   Rendered devise/registrations/new.html.erb within layouts/application (73.9ms)
2014-07-11T10:02:24.515127+00:00 app[web.1]: 
2014-07-11T10:02:24.515132+00:00 app[web.1]: ActionView::Template::Error (undefined method `username' for #<User:0x007f2b303b0378>):
2014-07-11T10:02:24.515134+00:00 app[web.1]:      8:   <%= f.email_field :email, autofocus: true %></div>
2014-07-11T10:02:24.515136+00:00 app[web.1]:      9: 
2014-07-11T10:02:24.515138+00:00 app[web.1]:     10:   <div><%= f.label :username %><br />
2014-07-11T10:02:24.515140+00:00 app[web.1]:     11:   <%= f.text_field :username, autofocus: true %></div>
2014-07-11T10:02:24.515142+00:00 app[web.1]:     12: 
2014-07-11T10:02:24.515145+00:00 app[web.1]:     13:   <div><%= f.label :password %><br />
2014-07-11T10:02:24.515147+00:00 app[web.1]:     14:     <%= f.password_field :password, autocomplete: "off" %></div>
2014-07-11T10:02:24.515150+00:00 app[web.1]:   app/views/devise/registrations/new.html.erb:11:in `block in _app_views_devise_registrations_new_html_erb__2151626084088518473_69911734787000'
2014-07-11T10:02:24.515152+00:00 app[web.1]:   app/views/devise/registrations/new.html.erb:4:in `_app_views_devise_registrations_new_html_erb__2151626084088518473_69911734787000'
2014-07-11T10:02:24.515154+00:00 app[web.1]: 
2014-07-11T10:02:24.515156+00:00 app[web.1]: 
2014-07-11T10:02:24.510327+00:00 app[web.1]: Completed 500 Internal Server Error in 195ms

我没有做过任何数据库迁移之类的事情。

对我来说,本地一切正常,但在 Heroku 上它给出了动作视图错误,这有点连线。

当然,在我从 git 推送带有附加字段“用户名”的新视图和控制器之前,它在 Heroku 上运行良好。

【问题讨论】:

  • 如果我从用户字段的 new.html.erb 行中删除,我的意思是:&lt;div&gt;&lt;%= f.label :username %&gt;&lt;br /&gt; &lt;%= f.text_field :username, autofocus: true %&gt;&lt;/div&gt; 它再次起作用。

标签: ruby-on-rails heroku ruby-on-rails-4 devise


【解决方案1】:

问题解决了。 heroku 上的数据库存在问题。表中的列用户名丢失,因为迁移文件丢失了,我没有注意到。感谢@John Beynon 的建议,问题出在数据库上

【讨论】:

    【解决方案2】:

    您需要执行heroku run rake db:migrate,以便在应用启动时 ActiveRecord 初始化获取模型的属性并可供表单助手使用。

    【讨论】:

    • 谢谢,但我刚刚尝试了heroku run rake db:migrate 和之后heroku restert,但问题是一样的
    • 而且我更改了控制器,而不是模型 - 仅在 application_cotnroller 中更改。就像我在上面粘贴的链接一样。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-26
    • 1970-01-01
    相关资源
    最近更新 更多