I have a model Country and it has a string attribute 'name_en' which value can be for example "England" or "[India]". How can I order properly by this attribute?
-
give an example of what you have tried and why it does not work...that would be helpful in knowing what the problem is.tihom– tihom2013-10-25 09:12:10 +00:00Commented Oct 25, 2013 at 9:12
-
define what "properly" means to you. Do you want to ignore the square brackets around 'India' and have it come after 'England' alphabetically?Pavling– Pavling2013-10-25 10:43:19 +00:00Commented Oct 25, 2013 at 10:43
Add a comment
|
1 Answer
You really need to read the documentation before you can go any far with rails. What you need (and a lot more) is explained here:
- http://guides.rubyonrails.org/active_record_basics.html
- http://api.rubyonrails.org/classes/ActiveRecord/Base.html
And to order by name you should:
Country.order('name_en').all