From Ruby on Rails: best method of handling currency / money, how do you generate a scaffold for the folowing:
add_column :items, :price, :decimal, :precision => 8, :scale => 2
Such as:
rails generate scaffold LineItem name:string \ price:decimal {:precision => 8, :scale => 2}
Also, what is the correct term for "extra description" for the decimal type?
Working in Rails 3.07, Ruby 1.92
To generate a fully working scaffold for a new object, including model, controller, views, assets, and tests, use the rails g scaffold command. Then you can run rake db:migrate to set up the database table. Then you can visit http://localhost:3000/widgets and you'll see a fully functional CRUD scaffold.
Scaffolding in Ruby on Rails refers to the auto generation of a simple set of a model, views and controller usually for a single table. For example: user@localhost$ ./scripts/generate scaffold users. Would create a full CRUD (create, read, update, delete) web interface for the Users table.
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}
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