4
我有以下兩種模式如何更新與導軌形式多模型
class Office < ActiveRecord::Base
has_many :locations, :dependent => :destroy
end
class Location < ActiveRecord::Base
belongs_to :office
end
我有一個辦事處模型new.html.erb
和下面的代碼在OfficeController
def create
@office = Office.new(params[:deal])
if @office.save
redirect_to office_url, :notice => "Successfully created office."
else
render :action => 'new'
end
end
如何添加字段Location
模型new.html.erb
的Office
?
我希望能夠在同一個表單中有位置的字段。