gpt4 book ai didi

ruby-on-rails - Heroku 只有 : ancestry gem crashes with undefined method `ancestry' for #

转载 作者:行者123 更新时间:2023-12-04 05:44:41 24 4
gpt4 key购买 nike

我在 Heroku 上只看到了祖先 gem 的问题(无法在本地复制):
https://github.com/stefankroes/ancestry

home#upload 中发生 NoMethodError:
#的未定义方法`祖先'

方法如下所示:

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

这是日志:

A NoMethodError occurred in home#anthem_upload:

undefined method `ancestry' for #<Anthem:0x007f1684d58b98>
app/controllers/home_controller.rb:335:in `anthem_upload'

最佳答案

您必须运行迁移才能添加方法 ancestry到您的模型:

 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

关于ruby-on-rails - Heroku 只有 : ancestry gem crashes with undefined method `ancestry' for #<Model:0x#######>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32899816/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com