Forum: Ruby on Rails How to check for presence of particular value entered ?

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.
8c70506408fddb9740b4de7339055c77?d=identicon&s=25 Prashant Tiwari (tiwaripk)
on 2006-03-17 07:34
Hi,

I am entering value in textbox ("name") on form. Now name field in
database is having 'unique' constraint on it so that no 2 records with
same name allowed in database. Now when I m trying to enter same name
into database from my form I m getting following error.
================================
Mysql::Error: #23000Duplicate entry 'Prashant' for key 2: INSERT INTO
users (`name`, `password`) VALUES('Prashant', 'Twiari')
================================

Instead of this error I want the Proper message should be displayed on
same page ("Form page") with name textbox highlighted. How to do that?
Also How to check presence of particular field value against the value I
ve entered in form so that I can authenticate user for logging in?

Please tell me .

Thanx in advance.
Prash
C1e5a9e9344b6d31b9df7303e6dc378a?d=identicon&s=25 Craig White (Guest)
on 2006-03-17 07:53
(Received via mailing list)
On Fri, 2006-03-17 at 07:34 +0100, Prashant Tiwari wrote:
>
> Instead of this error I want the Proper message should be displayed on
> same page ("Form page") with name textbox highlighted. How to do that?
> Also How to check presence of particular field value against the value I
> ve entered in form so that I can authenticate user for logging in?
>
> Please tell me .
----
you need to do a little background work...

start here...
http://wiki.rubyonrails.org/rails/pages/Understand...

the Agile Web Development With Rails is an excellent source of all this
information - you might want to buy the book in paper or PDF form from
your bookseller or from here...

http://www.pragmaticprogrammer.com/bookshelf/index.html

Craig
B07c187ac858535358faa9365b66e657?d=identicon&s=25 John Tsombakos (Guest)
on 2006-03-17 07:53
(Received via mailing list)
You want to use
 validates_uniqueness_of :name
in your model definition.

<http://api.rubyonrails.com/classes/ActiveRecord/Va...

And it will be checked upon save of the record.

jt
F3dc06f587d1ff4c7366b102bfda9204?d=identicon&s=25 David Mitchell (Guest)
on 2006-03-17 07:59
(Received via mailing list)
And as far as showing a nice error message goes, you might want to
check out 'flash' in the API...

Regards

Dave M.
This topic is locked and can not be replied to.