Browse the Ruby on Rails Community.

You are here: Forums Ask a Rails expert magic timestamps...

Replytotopic

magic timestamps

Posted in Forums : Ask a Rails expert

 
Profile

Authority 12
Posting Rating 0
Sign in to rate this post

It surely must be my host, but the created_at field gets populated in the database but when i try to access it, using @company.created_at it is nil
See the below – does this happen to everyone ?

@company = Company.find(:first)
=> #<company 0 id:>
te”, address_line_2: nil, city: “Do Not Delete”, state: “Do Not Delete”, country
_id: 1, parent: 0, licence: “0”, sales_tax_number: “0”, max_range_limits: 0, created_at: “2008-12-04 00:00:00”, updated_at: “2008-12-04 00:00:00”, created_by: 4
, updated_by: nil, ultimate_parent: nil, date_valid_from: nil, date_valid_to: ni
l, status: nil, max_number_replies: nil, company_name: “Acme”, domain_name: nil>
>> @company.created_at
=> nil
>>

 
20064666954644d813e6326

Authority 0
Posting Rating 74
Sign in to rate this post

Never had that happen.

I see you have a created_by attribute in there. Where and how is that being set. My guess is that you have something overriding the default rails timestamps and it is not working as expected. Does updated_at work as expected?

 
Profile

Authority 12
Posting Rating 0
Sign in to rate this post

I set the created_by using the current_user from restfulauthentication.

The thing I don’t get is that its getting populated from the active record, but when you access it then its nil.

 
Profile

Authority 12
Posting Rating 0
Sign in to rate this post

Sorry updated_at does not work either

 
Laleephoto3_150

Authority 12
Posting Rating 93
Sign in to rate this post

Odd… what does @company.attributes[‘created_at’] report?

And what happens if you use company=Company.find(:first) (without the ”@” prefix), and then try company.created_at?

 
Profile

Authority 12
Posting Rating 96
Sign in to rate this post

Certainly a weird problem. What database are you using? Can you go to the db console and execute “describe companies” so we can check the field types? Have you hooked into any of the ActiveRecord callbacks in your Company model? Do you get anything for company.updated_at_before_type_cast or company.created_at_before_type_cast ?

 
Me

Authority 37
Posting Rating 100
Sign in to rate this post

Colin: Does this happen with other records as well or is this the only record with problems? And, as Jon said, having those attributes’ values before typecast may help find the problem.

 
Profile

Authority 12
Posting Rating 0
Sign in to rate this post

It sounds like your Company model is doing something bad. Could you post a copy of it. Also what version of Rails are you on.

 
Profile

Authority 12
Posting Rating 0
Sign in to rate this post

Hi, Thanks for all your time and input sorry for the delay getting back long weekend here

I’m using SQLSERVER 2005.

@company.attributes[‘created_at’] reports
Thu Dec 04 00:00:00 +0000 2008

@company.created_at_before_type_cast reports
“2008/12/04 00:00:00”

and @company.created_at comes back with nil

code is

class Company < ActiveRecord::Base has_many :users has_many :employees validates_presence_of :company_registered_number, :message => “The Company Registered Number cannot be blank” validates_presence_of :address_line_1, :city, :state, :country, :parent, :ultimate_parent :message => “cannot be blank”

validates_numericality_of :max_number_replies,
     :message => "The number of replies must be a number" 
 validates_numericality_of :id, :on => :update,:greater_than => 0
   validates_uniqueness_of :company_name, 
       :message  => "This company name is already being used" 
 validates_uniqueness_of:licence, 
       :message  => "This licence is already being used" 
 validates_uniqueness_of:company_registered_number,
       :message  => "This company number is already being used" 
 validates_uniqueness_of:sales_tax_number,
   :message    => "This sales tax number is already being used" 
validates_format_of :company_name,
   :with    => /^.{2,}/,
   :message  => "A Company Name must contain one or more words"
 
Profile

Authority 12
Posting Rating 96
Sign in to rate this post
validates_presence_of :address_line_1, :city, :state, :country, :parent, :ultimate_parent :message => “cannot be blank”

There’s a comma missing on that line, before :message.

Can you paste your code again, but put html code tags around it?

 
Profile

Authority 12
Posting Rating 0
Sign in to rate this post

Hi, after much angst, i’ve tracked this down to an issue with a plugin – its the validate_dates plugin. I’m contacting the author for some advice.

Replytotopic

Other Recent Topics

Ask a Rails expert : Sanitizing html

Ask a Rails expert : First post, requesting sage perspective

Ask a Rails expert : How to use mephisto

Ask a Rails expert : How to use mephisto

Ask a Rails expert : will_paginate customization problem

Ask a Rails expert : BackgroundRB still wants 'development' environment...?

Ask a Rails expert : activescaffold, sql exception

Ask a Rails expert : Passing non-english chars in query string

Ask a Rails expert : Rails and 2D barcodes

Ask a Rails expert : apache giving proxy error

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