加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 仅限Heroku:祖先崩溃与未定义的方法’祖先’

发布时间:2020-12-17 04:39:44 所属栏目:百科 来源:网络整理
导读:我在Heroku上看到的问题只有祖先的宝石(不能在本地重现): https://github.com/stefankroes/ancestry home#upload中出现NoMethodError: #的未定义方法`ancestry’ 方法如下所示: def anthem_upload user = User.find_by(id: params[:user_id]) anthem = An
我在Heroku上看到的问题只有祖先的宝石(不能在本地重现):
https://github.com/stefankroes/ancestry

home#upload中出现NoMethodError:
#的未定义方法`ancestry’

方法如下所示:

def anthem_upload
    user = User.find_by(id: params[:user_id])
    anthem = Anthem.create!(user_id: user.id,body:params[:post]) <-- HAPPENS HERE
   ...
ene

此方法甚至不会调用.ancestry方法 – 但只要模型创建就会发生异常.

模型看起来像这样:

class Anthem < ActiveRecord::Base
  has_ancestry
 ...
end

这是日志:

06002

解决方法

您必须运行迁移才能将方法祖先添加到模型中:
heroku run rake db:migrate

当然假设您的应用程序在开发中工作.如果没有,您可以使用生成迁移

rails g migration add_ancestry_to_[table] ancestry:string

取自ancestry

编辑

看完你的评论后,我确实尝试了我的假设.将ancestry gem添加到不需要的项目中,并在我得到的控制台上将has_ancestry添加到模型Task而不进行迁移:

Loading development environment (Rails 4.2.2)
~/ (development) > Task.new
=> #<Task:0x00000008a3d088> {
               :id => nil,:project_id => nil,:name => nil,:description => nil,:points_budget => nil,:created_at => nil,:updated_at => nil
}
~/ (development) > Task.new.save
   (0.2ms)  BEGIN
   (0.2ms)  ROLLBACK
NoMethodError: undefined method `ancestry' for #<Task:0x00000008a9c998>
from /home/alejandro/.rvm/gems/ruby-2.2.2@rails4/gems/activemodel-4.2.2/lib/active_model/attribute_methods.rb:433:in `method_missing'
~/ (development) > Task.new.validate
NoMethodError: undefined method `ancestry' for #<Task:0x00000008ad1210>
from /home/alejandro/.rvm/gems/ruby-2.2.2@rails4/gems/activemodel-4.2.2/lib/active_model/attribute_methods.rb:433:in `method_missing'

你得到了同样的错误.当然,我正在发展中.你必须在heroku上尝试这样的东西:heroku run rails console

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读