Max Max - 17 days ago 5
Ruby Question

Concern is not loading in Rails 5

I have a basic Rails application and I am trying to use concerns for drying models. Everything goes fine in the development environment, but when I try to upload the app to Heroku, it constantly gives me this error:

/app/app/models/address.rb:3:in `<class:Address>': uninitialized constant Address::Persistable (NameError)


I tried to disable eager loading, but it didn't help.

Here is my Address Model:

class Address < ApplicationRecord

include Persistable

belongs_to :city
belongs_to :company

validates :city_id, :human, :lat, :lng, presence: true
end


And here is the module that I named "persistable", located at
app/models/concerns/persistable.rb


module Persistable
extend ActiveSupport::Concern

included do
scope :historical, -> { where(is_historical: true) }
scope :deleted, -> { where(is_deleted: true) }
default_scope { where(is_historical: false, is_deleted: false) }

def delete
update_attribute(:is_deleted, true)
end

def archive
update_attribute(:is_historical, true)
end

def revive
update_attribute(:is_historical, false)
update_attribute(:is_deleted, false)
end
end
end


What I already did:


  • tried to switch off eager loading

  • tried to move the
    Persistable
    module out of the
    concerns
    directory

  • tried to include the
    concerns
    path to the autoload configuration



Nothing worked, I still have this problem!

UPDATE

I did command form guide
rails r 'puts ActiveSupport::Dependencies.autoload_paths'
to check autoload_paths and I got:

D:/work/rails/www/app/models/concerns
D:/work/rails/www/app/assets
D:/work/rails/www/app/channels
D:/work/rails/www/app/controllers
D:/work/rails/www/app/helpers
D:/work/rails/www/app/jobs
D:/work/rails/www/app/mailers
D:/work/rails/www/app/models
D:/work/rails/www/test/mailers/previews

Max Max
Answer

Well, the problem was in Heroku server configuration. Seems like Heroku blocking constant name Persistable. Once I renamed every occurance of Persistable to Archivable, it just started to work. Why? Who knows =)