【问题标题】:Keep getting unidentified method 'field' for undefined method `bio' for #<User:>继续为#<User:> 获取未定义方法“bio”的未识别方法“field”
【发布时间】:2017-01-22 20:10:46
【问题描述】:

我刚刚将我的应用部署到 Heroku,我遇到了这个问题。在注册页面:

<div class="field">
    <%= f.label :bio %><br />
    <%= f.text_field :bio %>
  </div>

在日志中

ActionView::Template::Error (undefined method `bio' for #<User:0x007f5e772493c0>):
<div class="field">
        <%= f.label :bio %><br />
        <%= f.text_field :bio %>
      </div>

对此有什么想法吗?谢谢 附言。用于部署之前工作正常

编辑

我尝试迁移,但出现此错误

Couldn't create database for {"adapter"=>"sqlite3", "pool"=>5, "timeout"=>5000, "database"=>"db/test.sqlite3"}
Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 'sqlite3'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).

【问题讨论】:

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


    【解决方案1】:

    您尚未运行迁移,这就是它无法为用户找到 :bio 列的原因。

    在您的控制台上运行此命令

    heroku run rake db:migrate
    

    【讨论】:

    • 现在我得到 Gem::LoadError: Specified 'sqlite3' for database adapter,但 gem 没有加载。将gem 'sqlite3' 添加到您的 Gemfile(并确保其版本为 ActiveRecord 要求的最低版本)。
    • 尝试在开发中移动"sqlite3",在生产中移动"pg"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-17
    • 1970-01-01
    • 1970-01-01
    • 2011-07-02
    • 2012-05-15
    • 1970-01-01
    • 2014-12-11
    相关资源
    最近更新 更多