Nick Ginanto
Nick Ginanto

Reputation: 32130

Sorting Strings in Rails using Order

I Have a model "Msg" and it has a content as a string and a username as a string as well

at the moment all my Msgs have their content Lorem Ipsumed and I'd like to sort them out

I'm trying to do something like

Msg.all(:order => "content DESC")

but it will not sort the strings for me..

Is there anyway to sort the strings in one line to get all of the Msgs (or the actual strings)

Thanks

Upvotes: 0

Views: 499

Answers (1)

miguel.camba
miguel.camba

Reputation: 1827

Im not sure to understand the question.

Msg.all(:order => "content DESC")

retrieves all messages ordered by its content. Consequently, mapping its content attributes returns all the strings properly sorted

Msg.all(:order => "content DESC").map(&:content)

Upvotes: 1

Related Questions