How do I pass an argument to a has_many association scope in Rails 4?

The way is to define additional extending selector to has_many scope: class Customer < ActiveRecord::Base has_many :orders do def by_account(account) # use `self` here to access to current `Customer` record where(:account_id => account.id) end end end customers.orders.by_account(account) The approach is described in Association Extension head in Rails Association page. To access the Customer record in … Read more

ActiveRecord Rails 3 scope vs class method

There was more of a difference in Rails 2.x, since named_scopes did not execute your queries (so you could chain them), whereas class methods generally did execute the queries (so you could not chain them), unless you manually wrapped your query in a scoped(…) call. In Rails 3, everything returns an ActiveRecord::Relation until you need … Read more

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