I'm using Ruby on Rails with ActiveRecords. And it really makes me sick about all this datatypes like DateTime, Time etc. I render all data-related things on frontend, so i need just simple int when retrieving Timestamp from DB. Can i do it without having so many to_int
in my code?
Let's say i have migration like
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :email, null: false
t.string :crypted_password, null: false
t.string :password_salt, null: false
t.string :persistence_token, null: false
t.timestamps null: false
end
end
end
Then i do smth like
<%= @user.created_at =>
I have smth like 2015-02-11 14:11:04 UTC (because it's DateTime to_s in fact). While i need just 1423663864 (so i have to do smth like <%= @user.created_at.to_i =>). So it makes 4(!) conversion:
- DB 4 bytes int to DB string
- DB string to Ruby DateTime
- DateTime to int (the 4 bytes i had on first step)
- Ruby int to Ruby string