Creating model and index through one-line command?

Henley Chiu picture Henley Chiu · Sep 16, 2012 · Viewed 8.9k times · Source

I know I can easily create a model with this one line. Now suppose I want to add an index on username. How can I do so with one line without going to edit the migration file manually?

script/rails generate model TwitterUser username:string num_followers:integer num_following:integer bio:string location:string image:string num_tweets:integer website:string

Answer

Tonys picture Tonys · Sep 17, 2012

Rails version? New in 3.2, would be this:

rails generate model TwitterUser username:string:index num_followers:integer ...

You use scrip/rails generate so not sure if this helps you