Friday, January 20, 2006

ActiveRecord::StatementInvalid in Site#create

So I was getting the following error in my Ruby on Rails application.
Mysql::Error: Column 'added' cannot be null: INSERT INTO mytable (`added`, `highlight`, `modified`, `title`, `tags`, `tag_id`, `username`, `border`, `paid`, `desc`, `site_type`, `link`, `usersubmitted`) VALUES(NULL, '0', NULL, 'testing', '', 1, '', '0', '0', ' testing', '', 'testing', '0')

As is obvious, the column 'added' cannot be null. We can fix this by overriding the method create (this is the method where the "new" form is submitted to )

def create
@site = Site.new(@params['site'])
#we were getting "added cannot be null"
@site.added = Date.today
@site.modified = Date.today
if @site.save
redirect_to :action => 'list'
else
render_action 'new'
end
end



Add the delete link


<%= link_to "(delete)",
{:action => "delete", :id => site.id},
:confirm => "Really delete #{site.title}?" %>


5 Comments:

At 2:21 AM, Blogger Unknown said...

Haha, sunny day again! You know iam more excited when reading your articles here, you really made my day. What's more, you just tell the point of this question and it is informative enough now, thanks again for sharing here. runescape gold for sale , runescape gold

 
At 11:47 PM, Blogger Unknown said...

As is obvious, the column 'added' cannot be null. We can fix this by overriding the method create (this is the method where the "new" form is submitted to )swtor gold
buy swtor gold
cheap swtor gold
tor credits
buy tor credits
cheap tor credits

 
At 12:03 AM, Blogger Unknown said...

Online Marketing System Online Business Online Home Business Online Business Tips Internet Marketing Online Online Marketing Affiliate Marketing Online Marketing Success Selling Online Free Online Marketing Online Marketing Tools Online Marketing Blogguild wars 2 gold
buy guild wars 2 gold
cheap guild wars 2 gold
cheapest guild wars 2 gold
guild wars 2 gold for sale

 
At 3:55 AM, Blogger Richard Ressinger said...

Been looking for answer to this problem all over the web, thank you so much for providing solution, your blog is the best, will totally return here should I find any problems concerning ruby. Just in case you wouldn't need to search for solution for hours like I did, here's a link to best offer of cheap osrs gold available, ain't need to thank, just happy to help!

 
At 4:28 AM, Blogger ZedRS said...

Without a second thought, you should only use zedrs for all your Runescape gold swap needs.

 

Post a Comment

<< Home

eXTReMe Tracker