2013-04-23 3 views
0

차량 세부 정보, 불만 사항 및 사용자 세부 정보가있는 단일 양식이 있습니다. 차량 has_many 불만 사항 및 사용자 has_many 불만 사항. nested_attribute 양식이 있지만 어떤 이유로 협회가 잘못되었다고 느낍니다. 나는 조금 혼란스러워 양식이 있어야합니다 아니면 그것은 불만 hashone 차량 및 불만 has_one 사용자가 있어야 ?? 그리고 complaint.This 양식을 작성 IM 모든 인증이없는 새로운 사용자와 새로운 차량을 만드는 IM ..중첩 된 속성이있는 레일 3 복합 양식

Vehicle.rb

class Vehicle < ActiveRecord::Base 
    attr_accessible :number, :vehicle_types , :complaints_attributes 
    has_many :complaints 
    accepts_nested_attributes_for :complaints 
end 

User.rb

class User < ActiveRecord::Base 
    attr_accessible :address, :email_id, :mobile , :complaints_attributes 
    has_many :complaints 
    accepts_nested_attributes_for :complaints 
end 

불만 .rb

class Complaint < ActiveRecord::Base 
    attr_accessible :indecent_behaviour, :occurence_date_time, :other_complaints,  :place_occurence 
    belongs_to :user 
    belongs_to :vehicle 
end 

감사합니다.

답변

0

사용자와 차량이 중첩 된 불만 사항을 제기하는 이유는 이해가되지 않습니다. 새로운 사용자와 새 차량을 만드는 것과 동시에 불만을 제기하는 것은 아닙니다. 너?

아마도 사용자가 만들어지고 차량이 만들어지고 사용자가 차량에 대해 불평을하면 그 시점에서 불만이 제기됩니다. 사용자 또는 차량이 생성 될 때보 다 시간순으로 나중에 나타납니다.

그래서 중첩 속성을 가져올 수 있습니다. 대신 숨겨진 필드를 사용하여 차량 ID를 매개 변수로 전달하거나 중첩 된 리소스 경로를 사용하여 vehicle_id를 가져올 수 있습니다.

new_complaint_path(vehicle_id: @vehicle.id) 

을 불만 컨트롤러에 reply..Yes에 대한

def new 
    @complaint = current_user.complaints.build 
    @complaint[:vehicle_id] = params[:vehicle_id] 
end 
+0

덕분에 새로운 사용자와 새로운 차량을 만드는 메신저 메신저 불만을 만들 때 : 불평하는 CURRENT_USER의 has_many 협회를 통해 불만을 만들기 이 양식에는 인증이 없습니다 .. – shiva

관련 문제