开发者

Sorting query results using a model method

I have the following mapping (@location_matches represents a standard SQL query`:

 @matches = @location_matches.map { |listing|

    }.compact

When I go to my view, I can access @matches.username, etc, etc, etc.

However when I add this model method, I lose all access to any of the info!

 @matches = @location_matches.map { |listing|
           listing.compute_score(current_user)

    }.compact
开发者_开发问答

any ideas why? is there a better way to do this? thank ya


Here's sorting by computed score:

@matches = @location_matches.sort_by{|location| location.compute_score(current_user)}

http://www.ruby-doc.org/core/classes/Enumerable.html#M001481

Put .reverse at the end if you want it reverse-sorted.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜