-
-
Notifications
You must be signed in to change notification settings - Fork 16
Interval
Lucas Serrano edited this page Apr 12, 2017
·
7 revisions
Reads PostgreSQL's interval data type and transforms it into Rails' ActiveSupport::Duration
. PostgreSQL Docs
Just set the type of the column as interval
when creating a table.
create_table "courses" do |t|
t.string "title", null: false
t.interval "duration"
end
Or when you are adding or column, just use :interval
as type.
add_column :courses, :duration, :interval
The column is automatically identified and the value is turned into ActiveSupport::Duration
. So, any of the methods available on it can be used directly from your field. RubyOnRails Doc
# Shows when you'll be finishing the course
course.duration.from_now
Can't find what you're looking for? Add an issue to the issue tracker.