D
D
DartNyan2016-08-14 02:06:02
Ruby on Rails
DartNyan, 2016-08-14 02:06:02

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

I googled the examples - everything seems to be correct, but it swears by a bunch of syntax errors.
/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 '='

Rails 5.0, Ruby 2.3

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel Grudinkin, 2016-08-14
@Hunt666

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.

V
Vasily Shakhunov, 2016-08-14
@inf

conversations is an associated model? Might be worth doing a join .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question