Reputation: 3017
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?
Upvotes: 0
Views: 62
Reputation: 1268
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?
Upvotes: 1