0

I'm trying to sort my results by a method in that model but the model method needs some arguments, that's where I have problems. My model is called Event and I'm trying to use

Event.all.sort_by(&:user_score("2", "51.4980749", "10.8119977"))

The method user score needs some arguments

def user_score user_id, latitude, longitude  
  return 0 
end

The return 0 of course is just to test it but it already fails when I call the function:

SyntaxError: (irb):12: syntax error, unexpected '(', expecting ')'
...Event.all.sort_by(&:user_score("2", "51.4980749", ...

What am I doing wrong?

1 Answer 1

1

I'm sure, the problem is with calling method using block notation. i.e &:user_score("2", "51.4980749", "10.8119977")

Can you please try the same in more explicit way as follows,

Event.all.sort_by{|e| e.user_score("2", "51.4980749", "10.8119977")}

OR

Please find this post Can you supply arguments to the map(&:method) syntax in Ruby?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.