ActiveRecord OR query

If you want to use an OR operator on one column’s value, you can pass an array to .where and ActiveRecord will use IN(value,other_value): Model.where(:column => [“value”, “other_value”] outputs: SELECT `table_name`.* FROM `table_name` WHERE `table_name`.`column` IN (‘value’, ‘other_value’) This should achieve the equivalent of an OR on a single column

Rails ActiveRecord date between

Just a note that the currently accepted answer is deprecated in Rails 3. You should do this instead: Comment.where(:created_at => @selected_date.beginning_of_day..@selected_date.end_of_day) Or, if you want to or have to use pure string conditions, you can do: Comment.where(‘created_at BETWEEN ? AND ?’, @selected_date.beginning_of_day, @selected_date.end_of_day)

ActiveModel::ForbiddenAttributesError when creating new user

I guess you are using Rails 4. If so, the needed parameters must be marked as required. You might want to do it like this: class UsersController < ApplicationController def create @user = User.new(user_params) # … end private def user_params params.require(:user).permit(:username, :email, :password, :salt, :encrypted_password) end end

Float vs Decimal in ActiveRecord

I remember my CompSci professor saying never to use floats for currency. The reason for that is how the IEEE specification defines floats in binary format. Basically, it stores sign, fraction and exponent to represent a Float. It’s like a scientific notation for binary (something like +1.43*10^2). Because of that, it is impossible to store … Read more

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