Help: @album.release_date not coming out in view?

Hi everyone,

I need help.

I have a table called albums with various fields. One of them, the
one I’m having problems with, is release_date datetime. I generated a
model for Album, too, but currently there’s nothing in it.

I have a controller, called Public, that has, among other things:

def create
@album = Album.new
@album.title = ‘Aftermath’
@album.artist = ‘The Rolling Stones’
@album.release_date = ‘1967-01-01’
@album.genre = ‘Rock’

#@album.save

end

In my view, when I do a <%= debug(@album) %>, I get

— !ruby/object:Album
attributes:
artist: The Rolling Stones
title: Aftermath
genre: Rock
release_date: “1967-01-01”
new_record: true

*Note, I also tried “1967-01-01 12:00:00” but I got this error when
trying to do a @album.save (Mysql::Error: #22007Incorrect datetime
value: ‘1967-01-01T12:00:00Z’).

When I try to print out each attibute manually (calling @album.artist,
@album.genre, etc), I get:

ID -
Title - Aftermath
Artist - The Rolling Stones
Genre - Rock
Date -

Of course, there’s no ID since it hasn’t been saved into the database
yet. But date…?

Here’s my code to trace out the variables:

<% if @album != nil -%>
  ID - <%= @album.id %> <br />
  Title - <%= @album.title %> <br />
  Artist - <%= @album.artist %><br />
  Genre - <%= @album.genre %><br />
  Date - <%= @album.release_date %><br />
<% else -%>
  No record found.
<% end -%>

I’m stuck :o I need to be able to save this into the database. I’ve
searched other places about the error I get when trying to save, which
is “Mysql::Error: #23000Column ‘release_date’ cannot be null”, but I
haven’t found anything that solves my problem.

Thanks!

Ramon Miguel M. Tayag

Try putting a full date string and see if that solves your problem.

@album.release_date = ‘1967-01-01 12:00:00’

If it’s defined as a datetime field, SQL will want both the date and
time and may or may not assume the time as midnight if you don’t
supply it.

HTH,
Kevin S.

I’m stuck :o I need to be able to save this into the database. I’ve
searched other places about the error I get when trying to save, which
is “Mysql::Error: #23000Column ‘release_date’ cannot be null”, but I
haven’t found anything that solves my problem.

This maybe isn’t helpful… But, have you tried debugging it with:
@album.release_date = Time.now

Kevin,

Yup, I’ve tried that, too. See the section:

*Note, I also tried “1967-01-01 12:00:00” but I got this error when
trying to do a @album.save (Mysql::Error: #22007Incorrect datetime
value: ‘1967-01-01T12:00:00Z’).

Toby, I’ll have to get back to you on that :slight_smile: I’m currently not able
to check it out.

Thanks!

On 2/19/07, Kevin S. [email protected] wrote:

Kevin S.

Ramon Miguel M. Tayag

Oh my gosh! No wonder you name sounded familiar…

It’s your tutorial in Lynda I’m following :slight_smile: I was running it on a
Windows machine but now I’m trying it on FC6 (took me a week to put
the server up). I’ll update you on how it goes.

On 2/19/07, Kevin S. [email protected] wrote:

Kevin S.

Ramon Miguel M. Tayag

Well, it seems to be running just fine on Linux :o

On 2/19/07, Ramon Miguel M. Tayag [email protected] wrote:

Oh my gosh! No wonder you name sounded familiar…

It’s your tutorial in Lynda I’m following :slight_smile: I was running it on a
Windows machine but now I’m trying it on FC6 (took me a week to put
the server up). I’ll update you on how it goes.


Ramon Miguel M. Tayag