Retrieving created_at value in Rails?
Is there a way I could retrieve created_at
value from the Database in Rails?
The table has columns like ticket_created
, ticket_updated
. By default a created_at
column is also included. If I try doing:
@tickets = Ticket.find(:all)
for ticket in @tickets
puts ticket.created_at
end
the above code is returning ticket_created
instead of the automatically generated created_at
The sample database row looks like this.
id |开发者_Go百科 title | link | key | summary | priority | status | created_at | updated_at | ticket_created | ticket_updated
Try this to really put yourself at ease that the two columns contain different values.
Ticket.find(:all).map {|t|
{:attributes => t.attributes,
:created_at => t.created_at,
:ticket_created => t.ticket_created}
}.inspect
Then try t.created_at == t.ticket_created
to make sure they aren't equal and then lastly, rename the ticket_created
column to something_else
and see if that does the trick.
精彩评论