Rails where LIKE and array

I think You want to test all values with ILIKE function. This is how it’s done in Postgres: select * from table where value ilike any (array[‘%foo%’, ‘%bar%’, ‘%baz%’]); Try to convert to Rails/Ruby syntax like this: myarray_with_percetage_signs = [“name1″,”name2”].map {|val| “%#{val}%” } Product.where(“name ILIKE ANY ( array[?] )”, myarray_with_percetage_signs)

Rails 3 validates inclusion of when using a find (how to proc or lambda)

Just use a proc, like so: validates :currency_code, :presence => true, :inclusion => { :in => proc { Currency.all_codes } } validates :country_code, :presence => true, :inclusion => { :in => proc { Country.all_codes } } It’s worth noting for anyone else who may stumble across this that the proc also has the record accessible … Read more

How to save a model without running callbacks in Rails

I believe what you are asking for can be achieved with ActiveSupport::Callbacks. Have a look at set_callback and skip_callback. In order to “force callbacks to get called even if you made no changes to the record”, you need to register the callback to some event e.g. save, validate etc.. set_callback :save, :before, :my_before_save_callback To skip … Read more

Rails has_one with class name and foreign key

has_one :requester, :class_name => “User”, :foreign_key => “requester_id” This line (from the code that you posted) indicates that the requester is a User, and the table users should contain a column requester_id that is the foreign key toward friend_requests records. The rails error message states that the column requester_id does not exists (you have to … Read more

How to use Rails 4 strong parameters with has_many :through association?

Keep in mind that the name you give to your strong parameters (employees, employee_ids, etc.) is largely irrelevant because it depends on the name you choose to submit. Strong parameters work no “magic” based upon naming conventions. The reason https://gist.github.com/leemcalilly/a71981da605187d46d96 is throwing an “Unpermitted parameter” error on ’employee_ids’ is because it is expecting an array … Read more

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