2

How can I access models from a class in lib directory in rails application? I'm currently getting a uninitialized constant ClassName::ModelName when trying to access models. The error occurs when I try to run migrations(I'm transferring a Sinatra app to Rails)

The model is in app/models/parsed_company.rb

class ParsedCompany < ActiveRecord::Base
end

The class in lib directory is defined as follows

class DefaultMergeStrategy
  COMPANY_ATTRIBUTES = (ParsedCompany.column_names.map(&:to_sym) - [:created_at, :updated_at])
end
roman
  • 5,100
  • 14
  • 44
  • 77
  • 1
    If this is a model that inherits from `ActiveRecord::Base` then is should live in `app/models/[model_name].rb`. Can we get some of the code that you're using so we can have some context? – Kyle Decot Oct 24 '13 at 13:43
  • @Kyle Decot I've added some details. The model is in app/models directory – roman Oct 24 '13 at 13:53
  • It sounds like you want to ParsedCompany to inherit the attributes from your lib directory correct? – Deej Oct 24 '13 at 14:04
  • 1
    @David Actually I want to access my models from within lib directory – roman Oct 25 '13 at 10:58
  • Please see the following SO question: http://stackoverflow.com/questions/11632065/accessing-models-from-within-the-lib-directory-in-a-rails-3-project I am certain of it this should help you – Deej Oct 25 '13 at 11:26

0 Answers0