Various sorting needed for nine pages

Complete.
For months, ascending by month number,
For os sources, ascending by name,
For Color Depths, was a bit tricky, really wanted to get the 'All' record first, however numbers naturally appear before alpha, but this helped a lot. I was trying stuff like 'CASE WHEN depth LIKE '[0-9]%' THEN 2 ELSE 1 END, depth' but was able to use just 'depth +0 ASC' thanks to that hint!.
Resolution was tricker though and required

:order =>'length(resolution) +0 ASC'

to get the order right!
For browsers, ascending by browser name,
For Browser Version, ascending by Browser Name, Version, Sub-version.
For Operating Systems ascending by operating system name,
For Privileges ascending by privilege
For User ascending by user name.

Code changes (9 different controllers) were to add lines to find such as:

Months:        :order => 'month_num'
os_sources:        :order => 'source'
Browsers:          :order => 'browser_name'
Browser Versions:  :order => 'browser_id, version_name, sub_version_name'
Color Depths       :order => 'depth +0 ASC'
Operating Systems, :order =>'operating_system_name'  
Resolutions:       :order => 'length(resolution) +0 ASC'
Priv_lvls:         :order => 'priv_level'
Users:             :order => 'stats_user'


All tested out ok after a couple of minor issues.
Rails is great. Now I know the syntax (or exactly where to look) and what errors mean, etc. It all seems so much easier than initially! Plus my Ruby and Linux knowledge continues to grow too and of course that's always good!
More testing – found that percentage statistics edit/new also needed the new orders applied for resolutions and color_depths. I had made it commno code already, so that only one edit was needed once there for both functions at least, so semi-dry for now 😉
Testing2 – Also aligned color depths and resolutions correctly.

Performance Testing (Later): Found that the +0 method was making additional calls instead of cached ones. Still looking at that. Ultimately expecting to change field type in this app.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s