Option Switch Helper for Rails
There are always some options for your page. Perhaps the number of items to display (articles, picture, projects, …). Or the sort key for those. Preferably you set some sane defaults. But you’d like to enable your visitors to change those?
This is what I did first so people could change the sort order:
lengthy RHTML code for option switches
That way a link to the current sort order will be suppresed and you get the visual impresion of flipping a switch.
Remember DRY? Ain’t looking much like it as you keep adding options…
Application helpers to the rescue!
application helper for option switches
Put this function in your application_helper.rb (its not that lengthy if you ignore the last three arguments, they just add full compatibility to the link_to’s arguments).
Then call it this way:
nice RHTML for option switches
And in your controller you would be doing something like this
reading the options in your controller