Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 227
B Seven Avatar asked Mar 05 '12 00:03

B Seven


People also ask

How do you generate scaffold in rails?

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.

What is scaffold command in Ruby?

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.


1 Answers

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} 
like image 105
scarver2 Avatar answered Sep 22 '22 16:09

scarver2