How to generate scaffold for data type with "extra description" in Rails 3? How to generate scaffold for data type with "extra description" in Rails 3? ruby-on-rails ruby-on-rails

How to generate scaffold for data type with "extra description" in Rails 3?


In Rails 3.1 and below, the syntax is

rails generate scaffold LineItem name:string price:decimal

and then manually add the decimal properties to the migration file

t.decimal :price, :precision => 8, :scale => 2

In Rails 3.2, one can specify the decimal properties

rails generate scaffold LineItem name price:decimal{8,2}

NOTE: If you are running ZSH, the syntax requires a hyphen instead of a comma.

rails generate scaffold LineItem name price:decimal{8-2}

ANOTHER NOTE: If you are using bash under Mac OS X 10.9 try a dot instead of the comma

rails generate scaffold LineItem name price:decimal{8.2}


A few years later, with Rails 4.2 and bash (Linux) the following generator command works without problems:

bin/rails generate scaffold LineItem name:string price:decimal{8.2}

This will correctly generate the following example migration:

class CreateLineItems < ActiveRecord::Migration  def change    create_table :line_items do |t|      t.string :name      t.decimal :price, precision: 8, scale: 2      t.timestamps null: false    end  endend


Almost a year later. Rails 3.2.11. Regular bash shell. Rails scaffold creates mess with syntax field_name:decimal{p,s} regardless of railties official doc.The confusion lays in simple fact that curly braces are meta-characters in bash (as well as in other shells) and needs to be escaped. See logged issue 4602 in scaffold generator repo.

If you using bash then use dot instead of comma as workaround.
Correct scaffold syntax field_name:decimal{p.s}