All threads / How do I add a default time of 6:45pm

Ask A Question

Notifications

You’re not receiving notifications from this thread.

How do I add a default time of 6:45pm

Neil Patel asked in Rails

Hi

Following on from the my previous post

I want to add a new time column with the default of 6.46pm

I have tried this

class AddUsualStartTimeToAreas < ActiveRecord::Migration
def change
add_column :areas, :usual_start_time, :time, default: "18:45"
end
end

but it gives me a date?? which i don't want??

t.time    "usual_start_time",                         default: '2000-01-01 18:45:00'

its ok

in my area model i converted this to this usual_start_time.to_formatted_s(:time)
and is working

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 37,344+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.