Answer the question
In order to leave comments, you need to log in
Where is my error (scope)?
Hello.
I can't figure out what's wrong.
scope :between, -> (sender_id, recipient_id) do
where(“(conversations.sender_id = ? AND conversations.recipient_id = ? ) OR
(conversations.sender_id = ? AND conversations.recipient_id = ? )”,
sender_id, recipient_id, recipient_id, sender_id)
end
/home/dartnyan/Projects/instagram_app/app/models/conversation.rb:10: syntax error, unexpected '?' ...“(conversations.sender_id = ? AND conversations.recipient_... ... ^ /home/dartnyan/Projects/instagram_app/app/models/conversation.rb:10: syntax error, unexpected '?' ... conversations.recipient_id = ? ) OR ... ^ /home/dartnyan/Projects/instagram_app/app/models/conversation.rb:11: syntax error, unexpected '?' ... (conversations.sender_id = ? AND conversations.recipient_... ... ^ /home/dartnyan/Projects/instagram_app/app/models/conversation.rb:11: syntax error, unexpected '?' ... conversations.recipient_id = ? )”, ... ^ /home/dartnyan/Projects/instagram_app/app/models/conversation.rb:12: syntax error, unexpected ')', expecting '='
Answer the question
In order to leave comments, you need to log in
rusrails.ru/active-record-query-interface Section
14.1.
There, the scope with the argument looks like this "scope :created_before, ->(time) { where("created_at < ?", time) }"
Your quotes seem to be wrong.
conversations is an associated model? Might be worth doing a join .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question