Rails database defaults and model validation for boolean fields

From here If you want to validate the presence of a boolean field (where the real values are true and false), you will want to use validates_inclusion_of :field_name, :in => [true, false] This is due to the way Object#blank? handles boolean values. false.blank? # => true Or in Rails3 way validates :field, :inclusion => {:in … Read more

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

Multiple table joins in rails

To rewrite the SQL query you’ve got in your question, I think it should be like the following (though I’m having a hard time fully visualizing your model relationships, so this is a bit of guesswork): RagaContextApplicantsSong. joins(:raga_contest_applicants => [:raga_content_rounds], :contest_cat). group(‘raga_contest_rounds.contest_cat_id’) …such that the joins method takes care of both of the two joins … Read more

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