【问题标题】:Rails won't find a method that I addedRails 找不到我添加的方法
【发布时间】:2017-04-20 12:15:13
【问题描述】:

我创建了一个迁移并运行了rake db:migrate,但它说它不存在。在我的 IDE 中,它没有给我一个错误,但也没有将它保存在数据库中。它给了我 Heroku 生产版本的错误。

架构

  create_table "reviews", force: :cascade do |t|
    t.string   "name"
    t.text     "description"
    t.integer  "rating"
    t.integer  "user_id"
    t.datetime "created_at",  null: false
    t.datetime "updated_at",  null: false
    t.text     "pros"
    t.text     "cons"
    t.string   "category"
  end

表格,查看:https://hastebin.com/otisoqibon.js

  <div class="field">
    <p class="flow-text">Category</p>
    <%= f.text_field :category, :class => "grey lighten-2 autocomplete", :id => "autocomplete-input", %>
  </div>

控制器

 def new
    @review = Review.new
  end

错误

 - 2017-04-20T01:49:22.051420+00:00 app[web.1]:
   ActionView::Template::Error (undefined method `category' for ):
 - 2017-04-20T01:49:22.051421+00:00 app[web.1]:     17:   </div>
 - 2017-04-20T01:49:22.051423+00:00 app[web.1]:     19:     <p class="flow-text">Category</p>
 - 2017-04-20T01:49:22.051422+00:00 app[web.1]:     18:   <div class="field">
   - 2017-04-20T01:49:22.051424+00:00 app[web.1]:     20:     <%= f.text_field :category, :id => "autocomplete-input", :class => "grey
   lighten-2 autocomplete" %>
   - 2017-04-20T01:49:22.051424+00:00 app[web.1]:     21:   </div>
   - 2017-04-20T01:49:22.051425+00:00 app[web.1]:     22:   <div class="field">
   - 2017-04-20T01:49:22.051426+00:00 app[web.1]:     23:     <p class="flow-text">Pros, Woof Woof</p><br>

【问题讨论】:

  • 你好,可以添加全文吗?您是否在运行迁移后重新启动了服务器?
  • 我重新启动了它,但我仍然收到错误:/
  • 在重启之前尝试spring stop
  • 在本地环境中通过rake db:migrate:status检查迁移状态并检查其状态是否为down
  • 这是请求的全部日志吗?未定义的方法“类别”是什么,我看不到。

标签: ruby-on-rails ruby schema


【解决方案1】:

我猜那是因为你还没有在 heroku 上运行你的 rake db:migrate 任务。

heroku run rake db:migrate

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-13
    • 1970-01-01
    • 1970-01-01
    • 2018-01-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多