... | @@ -12,20 +12,20 @@ create_table "courses" do |t| |
... | @@ -12,20 +12,20 @@ create_table "courses" do |t| |
|
end
|
|
end
|
|
```
|
|
```
|
|
|
|
|
|
Or when you are adding or column, just use `:interval` as type.
|
|
Or when you are adding a column, just use `:interval` as its type.
|
|
```ruby
|
|
```ruby
|
|
add_column :courses, :duration, :interval
|
|
add_column :courses, :duration, :interval
|
|
```
|
|
```
|
|
|
|
|
|
### Using it
|
|
### Using it
|
|
|
|
|
|
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](http://api.rubyonrails.org/classes/ActiveSupport/Duration.html)
|
|
The column is automatically identified and its value turned into `ActiveSupport::Duration`. So, any methods available on it can be used directly from your field. [RubyOnRails Doc](http://api.rubyonrails.org/classes/ActiveSupport/Duration.html)
|
|
```ruby
|
|
```ruby
|
|
# Shows when you'll be finishing the course
|
|
# Shows when you'll be finishing the course
|
|
course.duration.from_now
|
|
course.duration.from_now
|
|
```
|
|
```
|
|
|
|
|
|
The value can be set in different manners:
|
|
The value can be set in some different manners:
|
|
```ruby
|
|
```ruby
|
|
course.duration = 1.year # A new instance of ActiveSupport::Duration
|
|
course.duration = 1.year # A new instance of ActiveSupport::Duration
|
|
course.duration = [1, 2, 3, 4, 5, 6] # A list of values for the given order Y-M-D H:M:S
|
|
course.duration = [1, 2, 3, 4, 5, 6] # A list of values for the given order Y-M-D H:M:S
|
... | | ... | |