Forum: Ruby on Rails Mysql::Error: Duplicate entry

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Rt R. (Guest)
on 2009-01-28 23:14
hello , I am designing a project for a  news website and I am new to ROR
I am facing a problem with the add news function

this is the error

Mysql::Error: Duplicate entry '' for key 1: INSERT INTO `articals`
(`body`, `title`, `date`, `tag`) VALUES('nnn', 'llllhhh', '2008-03-02',
'tttt')

-----
this is my code

class ArticleController < ApplicationController

def new

@article = Article.new
@article.date = Date.today
end

def create
@article = Article.new(params[:article])
if @article.save
redirect_to :action => 'list'
else
render :action => 'new'
end
 end

------
add.rhtml in views

<h1>Add new article</h1>
<% form_tag :action => 'create' do %>
<p><label>Title</label>:
<%= text_field 'article', 'title' %></p>
<p><label>Body</label>:
<br />
<%= text_area 'article', 'body' %></p>

<p><label>Date</label>:
<%= text_field 'article', 'date' %></p>

<p><label>Tag</label>:
<%= text_field 'article', 'tag' %></p>

<%= submit_tag "Create" %>
<% end %>
<%= link_to 'Back', {:action => 'list'} %>
 ------

please help :(
Frederick C. (Guest)
on 2009-01-29 02:44
(Received via mailing list)
On 28 Jan 2009, at 21:14, Rt Rr wrote:

> '2008-03-02',
> 'tttt')
>
sounds like you've got a unique index somewhere.

Fred
Rt R. (Guest)
on 2009-01-29 16:47
Frederick C. wrote:
> On 28 Jan 2009, at 21:14, Rt Rr wrote:
>
>> '2008-03-02',
>> 'tttt')
>>
> sounds like you've got a unique index somewhere.
>
> Fred

it's work now :)

thx very much Fred
This topic is locked and can not be replied to.