eta*_*luz 8 ruby-on-rails ancestry
我在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
Run Code Online (Sandbox Code Playgroud)
此方法甚至不会调用.ancestry方法 - 但只要模型创建就会发生异常.
模型看起来像这样:
class Anthem < ActiveRecord::Base
has_ancestry
...
end
Run Code Online (Sandbox Code Playgroud)
这是日志:
Run Code Online (Sandbox Code Playgroud)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
Run Code Online (Sandbox Code Playgroud)
当然,假设您的应用程序可以在开发中使用。如果没有,您可以使用以下命令生成迁移
rails g migration add_ancestry_to_[table] ancestry:string
Run Code Online (Sandbox Code Playgroud)
取自祖先
已编辑
读完你的评论后,我确实尝试了我的假设。将 gem添加ancestry到不需要的项目中,并将它们添加has_ancestry到 model 中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'
Run Code Online (Sandbox Code Playgroud)
你得到同样的错误。当然,我正在开发中。你必须在heroku上尝试这样的事情:heroku run rails console
| 归档时间: |
|
| 查看次数: |
174 次 |
| 最近记录: |