Browse the Ruby on Rails Community.

You are here: Forums Ask a Rails expert Problems with the use of time ...

Replytotopic

Problems with the use of time in the migration

Posted in Forums : Ask a Rails expert

 
Profile

Authority 0
Posting Rating 0
Sign in to rate this post

Hi!

I created a table like this:
[code=]create_table :work_items do |t| t.date :execution_date t.string :section t.integer :member_id t.time :duration t.text :description

t.timestamps
end[/code]
I need the duration field to enter something like HH:MM. Just the time without a date.

When I enter it, everything seems fine… But when I return to the edit view I see the time formatted like 2000-01-01 10:23:00…

When I create a validate method in the model to check on the input, I allways get 2000-01-01 10:23:00, weird because I only entered 10:23…

This is the validate method in the model:
def validate puts duration # Results in 2000-01-01 10:23:00
end

Can anyone help me? I hoped time would work like date, with this column I don’t have any problems…

Or is there another way for me to enter a time in the database? I want to input the format HH:MM and later on I would like to calculate the total time from several records…

Thhnx!

 
Profile

Authority 12
Posting Rating 76
Sign in to rate this post

Hi,

your problem is quite the same to the post at the following URL:
http://www.workingwithrails.com/forums/4-ask-a-rails-expert/topics/281-creating-a-scheduling-application-in-rails-that-will-use-a-calendar

If you don’t use some third party plug in or time format library you would have to write/code+maintain a customize library for your customized requirements by using the ruby functions for date/time format conversions one of them is the strftime(‘time format parameters’) . That may take a high time cost if you are not an expert in RoR. So try to use some library.

Thanks
Shafiq

Replytotopic

Other Recent Topics

Ask a Rails expert : json gem error

Ask a Rails expert : Problem with break

Ask a Rails expert : activesupport string first method error

Ask a Rails expert : url_for broken ?

Ask a Rails expert : map.routes.rb pls help

Ask a Rails expert : how to h tag in controller

Ask a Rails expert : Problem with Restful routing and partial form

Ask a Rails expert : will_paginate, search and ajax

Ask a Rails expert : captcha

Ask a Rails expert : Mass Deletes in Admin Section

Formatting Help
  • *bold*       _italics_      
    bq. (quotes)
  • "DSC":http://www.dsc.net
  • * or # (lists)
or cancel