관련 Tenancy가 저장되지 않아 저장할 때 CheckIn 레코드를 가져올 수 없습니다. 내가 달리하여 PROPERTY_ID 부분을 포함 할 필요가Rails/ActiveRecord - 연결이 저장되지 않습니다.
def new
@check_in = CheckIn.new
@check_in.build_tenancy.property_id = params[:property_id]
end
: 나는 체크인 및 관련 주택 임대차을 모두 만들 수있는 체크인 새로운 액션을 원하는
class Property < ApplicationRecord
has_many :tenancies
end
class Tenancy < ApplicationRecord
belongs_to :property
has_many :check_ins
end
class CheckIn < ApplicationRecord
belongs_to :tenancy
accepts_nested_attributes_for :tenancy
end
:
나는 협회와 세 가지 모델이 임차가 저장되지 않습니다.
check_ins의 형태/new.html.erb :
<%= form_for @check_in, url: property_check_ins_path do |f| %>
<%= f.label :date_time %>
<%= f.datetime_select :date_time, {minute_step: 15} %>
<%= f.label :tenancy %>
<%= f.fields_for :tenancy do |i| %>
<%= i.date_select :start_date %>
<% end %>
<%= f.submit "Create Check In" %>
<% end %>
내가 추가 한 임대는 CheckInsController에 강한 PARAMS 속성을 :
def check_in_params
params.require(:check_in).permit(:tenancy_id, :date_time, tenancy_attributes: [:start_date])
end
그것은 주목할 가치 년대 check_ins 노선이 속성에 중첩되어 있습니다.
resources :properties do
resources :check_ins, only: [:new, :create]
end
그래서 문제는 CheckInsController의 작업을 만들 때 내가 만든 임차가 사라졌습니다. 언제 어떻게 각각의 기록을 저장해야하는지, 그리고 내가 성취하려고 노력하는 것의 약간의 복잡성으로 인해 관련 도움말을 찾기가 어려워 졌는지 확실하지 않습니다.
내가 레일 5.
strong_params에 tenancy_attributes를 추가 했습니까? –
원래 질문에 감사합니다. –
감사합니다. 아, 그냥 가지고 있지 않다는 것을 깨달았습니다. 허용 된 매개 변수에 tenancy_id가 있습니다. 그런 다음 넣습니다. 안으로 들어가고 아직도 저장하지 않는다. –