Ramon Miguel M. Tayag
2007-Feb-19 13:02 UTC
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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
> > 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Kevin Skoglund
2007-Feb-19 14:14 UTC
Re: Help: @album.release_date not coming out in view?
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 Skoglund --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ramon Miguel M. Tayag
2007-Feb-19 14:50 UTC
Re: Help: @album.release_date not coming out in view?
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 :) I''m currently not able to check it out. Thanks! On 2/19/07, Kevin Skoglund <kevin-WGmuFPN42W8gMxX8nMqP6gC/G2K4zDHf@public.gmane.org> wrote:> > 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 Skoglund-- Ramon Miguel M. Tayag --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ramon Miguel M. Tayag
2007-Feb-19 15:00 UTC
Re: Help: @album.release_date not coming out in view?
Oh my gosh! No wonder you name sounded familiar... It''s your tutorial in Lynda I''m following :) 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 Skoglund <kevin-WGmuFPN42W8gMxX8nMqP6gC/G2K4zDHf@public.gmane.org> wrote:> > 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 Skoglund-- Ramon Miguel M. Tayag --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ramon Miguel M. Tayag
2007-Feb-19 15:13 UTC
Re: Help: @album.release_date not coming out in view?
Well, it seems to be running just fine on Linux :o On 2/19/07, Ramon Miguel M. Tayag <ramon.tayag-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Oh my gosh! No wonder you name sounded familiar... > > It''s your tutorial in Lynda I''m following :) 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---