I want to have a where clause with an equal and does not equal condition:
@user = User.where(:user_id => current_user.id, :author_id != current_user.id).nil? ? (render :something) : (render :somethingelse)
The above does not work:
syntax error, unexpected ')', expecting tASSOC ...d, :user_id != current_user.id).nil? ? (render :index) : (re...
If I change the second condition from !=
to =>
it will work, however.
How do I have both conditions in one where clase? Thank you
If you want to highlight the differences between two columns of data with conditional formatting you can do so with a simple formula that uses the" not equal to" operator (e.g. <>) and mixed references.
The "does not equal" operatorIf they are not equal, it will output TRUE , and if they are equal, it will output FALSE . This is the exact opposite functionality of the equals sign (=), which will output TRUE if the values on either side of it are equal and FALSE if they are not.
We can use the “Not equal to” comparison operator in Excel to check if two values are not equal to each other. In Excel, the symbol for not equal to is <>. When we check two values with the not equal to formula, our results will be Boolean values which are either True or False.
Here's how you would use Arel to generate the query "select * from users where user_id = ? and author_id != ?
":
users = User.arel_table User.where(users[:user_id]. eq(current_user.id).and( users[:author_id].not_eq(current_user.id)))
Using Arel isn't as concise as using Hash conditions for simple conditions, but it's a lot more powerful!
Here's a link to the full list of predications (eq
, not_eq
, gt
, lt
, etc.) available with Arel.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With