2011-11-17 98 views
0

我有一个模型 -Rails的关系

class Donor < ActiveRecord::Base #recipient has name:string email:string 
    has_one :recipient 
end 

class Recipient < ActiveRecord::Base #recipient has name:string address:string 
end 

捐助者已经填充到数据库中。

我有以下的路线 -

match "/:donor" =>"pages#donation", :as => :donor 

在这一行动,我有以下 -

@donor = Donor.find_by_name(params[:donor]) 

捐助者的名字已经在数据库中。

而且在我的观点 -

<%= form_for @donor do |f| %> 
    <div class="field"> 
    <%= f.label :name, "Name" %> #this is prepopulated with their name - but they can change it. 
    <%= f.text_field :name, :class=>"input-text" %> 
    </div> 
    <div class="actions"> 
    <%= f.submit "Submit" %> 
    </div> 
<% end %> 

我如何添加字段添加收件人的详细信息,以这种形式?

回答

0

如果我正确理解你,你需要嵌套的形式。看看,例如,在this伟大的文章。

+0

谢谢! accep_nested_attributes_for就是我正在寻找的东西。 – Finnnn