I’m trying to use the OR operator in my message controller to show conversation. I have tried two statements I found in here, but neither of them is working.
1st one:
@messages = current_user.messages.where(:sender_id => params[:sender_id]).OR(:reciptient_id => params[:sender_id])
ERROR: Or method not found
2nd one:
@messages = current_user.messages.where("sender_id = :sender_id OR recipient_id = :sender_id", {sender_id => params[:sender_id], :recipient_id => params[:sender_id]})
Error: undefined local variable or method sender_id
I’m using Rails 3.2. Could someone tell me what’s wrong in my code?
The second one is almost right, there is just a slight typo in it. It shoul be like this:
You missed the “:” before the sender_id.