Ruby on Rails Thursday, September 25, 2014

Jon Garvin wrote in post #148415:
> This should do it.
>
> <% for recipe in @recipes.sort{|a,b| a.title <=> b.title } %>

Jon Garvin .. you are awesome... I struggled the entire day yesterday
figuring out how to sort a dynamic list based on categories
alphabetically while working on creating a styleguide based on ruby. I
have no experience working on ruby. When i found this link via google i
finally got my Eureka Moment. Thanks once again for providing the code.

The magic code that helped me was .sort{|a,b| a<==>b}

just to provide the entire code in context i used is a below

<% for c in @categories.sort{|a,b| a <=> b} %>
<li><a href="<%= c[0] %>.html"><%= c[0] %></a></li>
<% end %>

i am wondering if i can use the same sorting filter in Jekyll...will
give a try.

thanks once again though

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/e2040095d03b8ead5529376e96020e08%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment