Posts

Showing posts with the label dynamic scope

rails scope with argument or dynamic value and join tables

scope :get_by_currency, -> (currency) {find_by(currency_id: currency)} scope :by_role, ->(role) { joins(:roles).where(roles: { name: role }) } //it will work in rails 4 and previous version scope :by_role, ->(role) { joins(:roles).where('roles.name ? ', #{role} ) } //it will work in all versions of rails validate  :validate_mimimum_amount, unless: -> (order) { order.ord_type=='market' || order.ord_type=='manual' }