0

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

1
  • What does that mean: It will not sort the strings for me? It sorts the msg-objects (descending) by the content of the objects. Or do you want to sort by usernames? Commented Oct 16, 2011 at 16:35

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. This still won't sort it for me (it does help me do other things). if I add .sort it gives it to me sorted.
It should. Msg.all(:order => "content DESC") return an array of messages ordered by the content, so mapind the content attribute returns the array of sortered contents. Try Msg.all(:order => "content ASC").map(&:content)

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.