Ruby on Rails generates model field:type - what are the options for field:type?
:primary_key, :string, :text, :integer, :float, :decimal, :datetime, :timestamp,:time, :date, :binary, :boolean, :references
See the table definitions section.
To create a model that references another, use the Ruby on Rails model generator:
$ rails g model wheel car:references
That produces app/models/wheel.rb:
class Wheel < ActiveRecord::Base belongs_to :carend
And adds the following migration:
class CreateWheels < ActiveRecord::Migration def self.up create_table :wheels do |t| t.references :car t.timestamps end end def self.down drop_table :wheels endend
When you run the migration, the following will end up in your db/schema.rb:
$ rake db:migratecreate_table "wheels", :force => true do |t| t.integer "car_id" t.datetime "created_at" t.datetime "updated_at"end
As for documentation, a starting point for rails generators is Ruby on Rails: A Guide to The Rails Command Line which points you to API Documentation for more about available field types.
$ rails g model Item name:string description:text product:references
I too found the guides difficult to use. Easy to understand, but hard to find what I am looking for.
Also, I have temp projects that I run the rails generate
commands on. Then once I get them working I run it on my real project.
Reference for the above code: http://guides.rubyonrails.org/getting_started.html#associating-models