how to require active record working outside of rails

Here’s how I’m using ActiveRecord outside of Rails: #!/usr/bin/ruby require ‘active_record’ require ‘mysql2’ # or ‘pg’ or ‘sqlite3’ ActiveRecord::Base.establish_connection( adapter: ‘mysql2’, # or ‘postgresql’ or ‘sqlite3’ database: ‘DB_NAME’, username: ‘DB_USER’, password: ‘DB_PASS’, host: ‘localhost’ ) # Note that the corresponding table is ‘orders’ class Order < ActiveRecord::Base end Order.all.each do |o| puts “o: #{o.inspect}” end

Retrieving array of ids in Mongoid

Remember that the ID is stored as :_id and not :id . There is an id helper method, but when you do queries, you should use :_id: User.where(:_id.in => arr) Often I find it useful to get a list of ids to do complex queries, so I do something like: user_ids = User.only(:_id).where(:foo => :bar).distinct(:_id) … Read more

Rails “is not a module” error

Ruby is telling you that it found an Insurance, but it is not a module. Perhaps you already have defined an Insurance class? Depending on the surrounding code it might help if you “reset” the namespace by prepending a double colon: broker = ::Insurance::Broker::FakeBroker.new(1234,1234)

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)