Monthly Archives: February 2014

No gravatar for me.

Thought about posting a nice sketch of me as an avatar for this blog, but after seeing that they condone hardcore sexual imagery or extreme violence then that’s not something I can support.

I’ll have to check the link between WordPress and Gravatar and decide on the future of the blog accordingly.

What’s the Rails way?

Right, I finally figured out the way to get tabular data sorted on the index page by way of a non-numeric associated table B, by way of a class method and scope (to limit the selection to the first letter of the name in table A) but it means that my controller needs to check the value the column selection param and run a different query when sorting by that column.

I could add a custom route to the controller and just render the index page. But that will probably mean splitting my session variable processing across different actions.

I guess what I really should do is put all the session processing in the before_action setup method and keep the index and custom actions neat and tidy.

And then there’s the question of the matter of the simple select form to display only items in table A that have a reference to table B as pointed to by the select.

Or perhaps I consider all this as basic search functionality and incorporate into the search actions that I will need to do anyway.

One step at at a time: tidy up the session handling.

When I say mud, I mean mud.

Finally, a break from the rain and a bit of sun. Out in the garden, red kites swirling overhead, planting the bulbs donated by father-in-law, digging in the garden manure and last year’s leaf mould and hoping that all the effort will help the soil.

An to finish, a couple of hours pulling out the twigs from the pile of leaves and bagging up for next year’s compost.

I’ll leave the glamour part of the gardening to my wife while I do the only stuff i can be safely entrusted to: the mud and rotting leaves.

I’m not writing a blog application or social network!

Why does every tutorial or rails example post assume only blogs are written? Does anyone actually use Rails for real stuff?

I’m writing a telephone extension allocation system to be used by FIM to disj out phone numbers to Lync; posts and comments have no relevance.

I say this because I need to work out how to do column sorting on association tables using left joins and I really can’t get my head around the finer points of ActiveRecord’s includes and joins to make any progress.

I nearly had it cracked with a (mostly) manual query but it broke will_paginate, having an array rather than AR relations. So near, yet so far.

I’m determined to crack this one, so I might go quiet for a little while.

Session handling with pagination

Having managed to improved the alphabetic pagination in my applications is due to better handling of the session tokens in the controller, but while going through Railscast 228 (more on tabular sorting to follow – using many:many associations if I can figure it out) Ryan mentioned the need for some basic security around the submitted data and I realised that I was assigning session vars directly from params.

But it’s easy enough to tidy up.

session.delete :letter if params[:q]
session[:letter] ||= ('a'..'z').include?(params[:q]) ? params[:q] : ''

Remove the session value if a query string param has been passed. Then if the session value doesn’t exist assign it from the params only if the patam value is in the range a-z; otherwise assign and empty string.

This works out well for me as the empty string is the cue to display all values by virtue of it being the value passed to the search scope.

But going back to the Railscast, I was really taken with this construct,

%w[asc desc].include?(params[:direction]) ?  params[:direction] : "asc"

for input sanitsation and realising while some of my recent stuff has been okay, I’ve still got a fair way to go.

Now, back to this column sorting…