I make a script to try some functions. But I cannot use models in lib. Interesting is, that I already have an lib, and there it works fine with the mostly same code(?).
// script/tags.rb:
require File.expand_path('../../config/application', __FILE__)
require 'company_tags'
host = ARGV[0] || 'team1.crm.tld'
c = CompanyTags.new(host)
c.run
// lib/company_tags.rb
class CompanyTags
def initialize(host)
@site = Site.where(host: host).first
end
def run
comp = @site.companies.first
comp.tag_list.add("tag1")
comp.general_list.add("tag_general")
comp.save!
p comp.tag_list
end
end
Error: /lib/company_tags.rb:3:in `initialize': uninitialized constant CompanyTags::Site (NameError)