Using Ruby on Rails combined with capistrano and git, I've run into an annoying problem..
I have a controller "people" with the index action that looks something like this:
def index
@people = Person.find( :conditions => params[:search] )
end
There is a boolean "is_admin" column in the Person table. Assuming that some of the people are admin and some are not, a get call to http://localhost:3000/people?search[is_admin]=true should populate @people with some users... And this is true for my local pc when I run the app in development mode..
But.... When I deploy to my server account ( railsplayground ), a call to http://mydomain.com/people?search[is_admin]=true fails to find any matching items. However, if I change ...?search[is_admin]=true to ...?search[is_admin]=1 the response returns the administrator users as expected...
Back on my local pc, the use of "1" instead of "true" fails.
The bottom line is that
Person.find( :all, :conditions => { :is_admin => 'true' } )
works my development environment, and
Person.find( :all, :conditions => { :is_admin => 1 } )
works in my deployed environment.
Why is this? and how can I fix it?
Ideally I would like to place links like:
link_to( "Administrators", {
:controller => '/people',
:action => :index,
:search => { :is_admin => true }
})
and get a lists of administrators :).
Might be worthy to note that my development database is a sqlite3 file, and production is a mysql database...
EDIT: I understand the objections to user-input, but in this exceptional case it is a very very minor threat. Also, my current code works perfectly in either my development pc, or my production account, but not on both. The easiest sollution seems to change the way sqlite3 saves and interperets boolean values, so I would change my question to "how do I change the way sqlite saves boolean values"... If sqlite would mimic mysql's behavior perfectly, it would serve my developments needs perfectly...