How to select where ID in Array Rails ActiveRecord without exception

If it is just avoiding the exception you are worried about, the “find_all_by..” family of functions works without throwing exceptions. Comment.find_all_by_id([2, 3, 5]) will work even if some of the ids don’t exist. This works in the user.comments.find_all_by_id(potentially_nonexistent_ids) case as well. Update: Rails 4 Comment.where(id: [2, 3, 5])

Can you get DB username, pw, database name in Rails?

From within rails you can create a configuration object and obtain the necessary information from it: config = Rails.configuration.database_configuration host = config[Rails.env][“host”] database = config[Rails.env][“database”] username = config[Rails.env][“username”] password = config[Rails.env][“password”] See the documentation for Rails::Configuration for details. This just uses YAML::load to load the configuration from the database configuration file (database.yml) which you can … Read more

What does inverse_of do? What SQL does it generate?

From the documentation, it seems like the :inverse_of option is a method for avoiding SQL queries, not generating them. It’s a hint to ActiveRecord to use already loaded data instead of fetching it again through a relationship. Their example: class Dungeon < ActiveRecord::Base has_many :traps, :inverse_of => :dungeon has_one :evil_wizard, :inverse_of => :dungeon end class … Read more

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