8

I'm seeing an issue on Heroku only with the ancestry gem (cannot reproduce locally): https://github.com/stefankroes/ancestry

A NoMethodError occurred in home#upload: undefined method `ancestry' for #

Method looks like this:

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

This method doesn't even call on .ancestry method - but the exception happens as soon as model is created.

Model looks like this:

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

Here is the logs:

A NoMethodError occurred in home#anthem_upload:

  undefined method `ancestry' for #<Anthem:0x007f1684d58b98>
  app/controllers/home_controller.rb:335:in `anthem_upload'
etayluz
  • 15,920
  • 23
  • 106
  • 151
  • Can you show the full error trace in the heroku log? – K M Rakibul Islam Oct 02 '15 at 03:05
  • show your `model_upload` method as well or thats the `anthem_upload` itself? – K M Rakibul Islam Oct 02 '15 at 03:19
  • model_upload is anthem_upload - same thing it's above. The weird thing is this all works well locally, only on Heroku it explodes – etayluz Oct 02 '15 at 03:29
  • yeah, the error message is not really saying anything. if you do a project wide search for `ancestry`, what do you get? where is it this method being called in your project? – K M Rakibul Islam Oct 02 '15 at 03:30
  • Inside, the model there's something you have to add for this gem called "has_ancestry" - and I believe the gem provides that method "ancestry" - except I suspect it's clashing with something on Heroku so it doesn't want to work in that environment – etayluz Oct 02 '15 at 03:33

1 Answers1

2

You must run the migration to add the method ancestry to your model:

 heroku run rake db:migrate

Of course assuming your app works at development. If not you can generate the migration with

rails g migration add_ancestry_to_[table] ancestry:string

Taken from ancestry

Edited

After read your comments, I did try my hypothesis. Adding the ancestry gem to a project that doesn't need, and them adding has_ancestry to the model Task, without migrations, at the console I got:

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'

The same error you got. Of course, I'm at development. You must try something like this at heroku with: heroku run rails console

Alejandro Babio
  • 5,189
  • 17
  • 28