Forum: Ruby on Rails validates problem

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.
Ead43bcb0202410540a6a7cee5955d46?d=identicon&s=25 Fresh Mix (giga)
on 2009-03-02 10:29
Validation:
  validates_presence_of :name
 validates_length_of :name, :maximum => 150
  validates_inclusion_of :category, :in => %w( X  Y XY )
  validates_length_of :gender, :maximum => 3
  validates_length_of :tag, :within => 1..10

Data sended

data: !map:HashWithIndifferentAccess
  name: Bond
  category: X
  tag: standard

Errors:

Category is not included in the list
Tag is too short (minimum is 1 characters)
Gender is too long (maximum is 3 characters)

What wrong?

Category is in list
Tag can't be too short, it 8 char
And gender can't be too long, because there is no gender value at all.
80e4cb97cae5c8d745f72337d93fd8f2?d=identicon&s=25 MaD (Guest)
on 2009-03-02 10:37
(Received via mailing list)
can you set a debugger in your Controller/Model to see what is
actually received?
0348be81e22f24afdaa6e4f137aa9dfc?d=identicon&s=25 Priya Buvan (priyadharsini)
on 2009-03-02 10:37
Try with following

validates_inclusion_of :category, :in => %w( X,  Y, XY )
validates_length_of :gender, :maximum => 3, :allow_nil => true
validates_length_of :tag, :in => 1..10
Ead43bcb0202410540a6a7cee5955d46?d=identicon&s=25 Fresh Mix (giga)
on 2009-03-02 17:09
MaD wrote:
> can you set a debugger in your Controller/Model to see what is
> actually received?

How can I se a debbuger?

>validates_inclusion_of :category, :in => %w( X,  Y, XY )
>validates_length_of :gender, :maximum => 3, :allow_nil => true
>validates_length_of :tag, :in => 1..10

gender works now, but tag and category nope.
661ae6e97d0e16c2af2aaf7d197e8387?d=identicon&s=25 Sijo k g (sijo)
on 2009-03-03 05:28
> How can I se a debbuger?
>
 You need to install ruby-debug gem first  Check if it already installed
 gem list

   write debugger  at the place where u want debugging and now start
your server like
./script/server --debugger   then you will get debug prompt Type h for
help to get available commands
example : to print any value say @var
p @var
0348be81e22f24afdaa6e4f137aa9dfc?d=identicon&s=25 Priya Buvan (priyadharsini)
on 2009-03-03 06:43
Fresh Mix wrote:
> MaD wrote:
>> can you set a debugger in your Controller/Model to see what is
>> actually received?
>
> How can I se a debbuger?
>
>>validates_inclusion_of :category, :in => %w( X,  Y, XY )
>>validates_length_of :gender, :maximum => 3, :allow_nil => true
>>validates_length_of :tag, :in => 1..10
>
> gender works now, but tag and category nope.

For tag also you give
validates_length_of :tag, :maximum=>10 like that and try.. you can give
minimum also in this..
This topic is locked and can not be replied to.