views:

77

answers:

2

I want to generate a model and the corresponding database table in rails using the generator script. The database table has a field with "enum" type. How can I generate it?

The table: create table works { id int unsigned not null auto_increment, nickname varchar(20) not null, sex enum('m', 'f'> not null };

the command: script/generator work nickname:string sex:(what should I write here?)

+1  A: 

You could just use a string and then add validation on the model like this:

validates_inclusion_of :sex, :in => %w( m f )

cakeforcerberus
+1  A: 

Unfortunately, the valid column types are: integer, float, datetime, date, timestamp, time, text, string, binary, and boolean

You can try making the column a string and going with the validates_inclusion_of route or you can try the enum_field plugin: http://github.com/giraffesoft/enum_field/tree/master

erik