新手问题。
我有两个彼此相关的模型:
class Relationship < ActiveRecord::Base
...
attr_accessible :source_item_id, :target_item_id
belongs_to :target_item, :class_name => "Item"
belongs_to :source_item, :class_name => "Item"
belongs_to :user
...
end
和
class Item < ActiveRecord::Base
...
attr_accessible :address
...
end
现在,在我的表单中,我已经知道了source_item_id。我希望能够在表单中输入地址,并创建target_item和相关的关系。
<%= form_for @new_relationship do |f| %>
<% @new_relationship.source_item_id = @current_item.id %>
<%= f.hidden_field :source_item_id %>
<%= f.submit "New Relationship" %>
<% end %>