Syntax to specify limit while generating a model

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?

Answers


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}"


I know this is old but does that syntax turn into a varchar() or a char(). is there a difinitive list of the syntax for the model generation that tells someone how to define everything from an index on one or more columns to contraints to null/not null,etc. I tried to add this as a comment to the previous answer but was unable to


Need Your Help

Managing helper death

python emacs rope ropemacs pymacs

I had installed Pymacs, rope, ropemode, ropemacs, and when I executed pymacs-terminate-servicesby accident, I couldn't save modified buffers. It first asked me - The Pymacs helper died. Restart it?...

GitLab email setup: sending via another mail server

ruby-on-rails ruby-on-rails-3 git smtp gitlab

By default gitlab has the next configuration in gitlab.yml :