Geoff
Geoff

Reputation: 9580

Outputting booleans for Rails in Heroku gives "t" instead of "true" and "f" instead of false?

I just added two new columns to my Users table in Rails and found some surprising results on Heroku compared with my local environment, and when compared with earlier Heroku usage! Do you know what might have happened?

This is the migration:

class AddMoreIntroFlagsToUsers < ActiveRecord::Migration def change add_column :users, :has_seen_first_intro, :boolean, :null => false, :default => false add_column :users, :has_seen_store_intro, :boolean, :null => false, :default => false end end

However, the following JavaScript in my view outputs t and f instead of true and false...

User.hasSeenStoreIntro = <%= signed_in? and current_user.has_seen_store_intro %>

converts to: (I was expecting true or false not t and f!)

User.hasSeenStoreIntro = t

This gives a JS error since t isn't defined!

Any idea why this would happen just for the new columns? It never did that for my old columns. A potentially related problem is that I ran a secure route to set user. has_seen_first_intro = true and user.has_seen_store_intro = true for all existing users, yet those columns did not update to true. I had run similar code after adding earlier columns, and it used to work. What changed now?

The only thing that I can think changed is that the number of users in my production table has grown significantly in the past few days.

Upvotes: 0

Views: 389

Answers (3)

Sandeep Kapil
Sandeep Kapil

Reputation: 992

Anybody still facing this issue on heroku, Try to restart app

heroku restart --app yourappname

Upvotes: 1

Pavling
Pavling

Reputation: 3963

IIRC Rails' SQLite adapter defaults booleans to t/f

To be DB agnostic, you could try to use Rails' automatic evaluation of boolean fields

signed_in? and current_user.has_seen_store_intro?

edit: If fact that may not work, and you might want to try to solution as per this post

Upvotes: 1

Mike Campbell
Mike Campbell

Reputation: 7978

Maybe you have 't' stored in your database for a true value for current_user.has_seen_store_intro, possibly because it was added by a different database adapter that supports booleans being stored as 't' and 'f'. Let's assume that signed_in? returns true -- in which case:

1.9.3p194 :008 > a = true
 => true 
1.9.3p194 :009 > b = 't'
 => "t" 
1.9.3p194 :010 > a and b
 => "t"

That's in Heroku. In your dev environment your database adapter understand 't' and 'f' as boolean values, therefore it returns true.

Just a possibility.

Upvotes: 0

Related Questions