我有以下数据库架构:
create_table "addresses", :force => true do |t|
t.string "road"
t.string "city"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "client_id"
end
create_table "clients", :force => true do |t|
t.integer "address_id"
t.integer "order_id"
t.string "first_name"
t.string "last_name"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "orders", :force => true do |t|
t.integer "order_id"
t.integer "client_id"
t.datetime "created_at"
t.datetime "updated_at"
end
end
和型号:
class Client < ActiveRecord::Base
belongs_to :address
end
class Order < ActiveRecord::Base
belongs_to :client
end
class Address < ActiveRecord::Base
end
此设置的目的是记录许多客户端,每个客户端都有一个地址。多个客户端可以有相同的地址。地址表中的 client_id 用于此目的。
当我访问 /Clients ActiveScaffold 视图并单击创建时,我可以为新客户输入数据,包括客户新地址的数据。
但是,当我访问 /Orders 视图并单击创建时,我可以添加一个新客户并为他输入数据,但是对于地址只有一个选择框,它只能用于选择现有地址,有没有为新客户创建新地址的字段。如何包含新客户的地址字段,以便为客户创建新地址?
提前致谢