in rails, we can generate the model like this
rails generate model post title:string body:text published:boolean
And the command has following syntax as per the rails guide
$ rails generate model
Usage: rails generate model NAME [field:type field:type] [options]
I am wondering if its possible to specify limit/length for each field as part of [options]
? Further, what is the use of [options]
parameter?
You can provide the limit with braces:
rails g model Session session_id:string{40} user_agent:string{200}
In rails 5 I had to use rails g model User name:"string{16}"
You need to give the size in the curly braces, which will get transformed into limits
rails generate model MyModel some_id:integer{20} some_name:string{255}
some_text:text some_int:integer{1} some_deci:decimal{10,2}
You can also have other data types such as boolean, date, time, datetime, float, binary etc..
Options are something like 'do you also need to run migration' or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With