Rails表单中的关系

时间:2011-11-17 15:56:40

标签: ruby-on-rails ruby-on-rails-3

我有一个模特 -

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 %>

如何添加字段以将收件人详细信息添加到该表单?

1 个答案:

答案 0 :(得分:0)

如果我理解正确,您需要嵌套表格。例如,请查看this精彩文章。