Make Ruby on Rails select_tag stick
I spend a couple hours yesterday trouble shooting a very minor bug in my code that had be grinding my teeth. This was the link of code
Hidden: </label><%= select_tag :hidden, options_for_select({'No' => 0, 'Doesn\'t Matter' => -1 ,'Yes' => 1}, params[:hidden]) %>
The problem here, was the last part of this code "params[:hidden] should be setting the default correctly every time the page is called again. The problem is, the contents of params[:hidden] is in string format while it should be in int format. This is an easy fix all you have to do is something like ....
params[:hidden].to_i
And your done. So in conclusion, pay attention to your data types! Ruby doesn't always handle eveything for you.
- The Net Duck
Here is the funished line that works.
Hidden: </label><%= select_tag :hidden, options_for_select({'No' => 0, 'Doesn\'t Matter' => -1 ,'Yes' => 1}, params[:hidden].to_i) %>


