2012-03-28 2 views
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 %> 

답변

0

일반적으로 컨트롤러에서 관계를 수행하고 양식에서 데이터를 수집하도록합니다. 두 가지 모델로 양식을 작성하는 방법을 묻는 경우이 게시물 here을 확인하십시오. 나는 당신의 질문을 바로 이해하기를 바랍니다!

관련 문제