0
새내기의 질문은 여기에 있습니다.레일 형태의 관련 모델을 만드는 방법
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 %>