私はcompany_profileオブジェクトに一連のユーザーを追加しようとしています。アイデアは、ユーザーが会社を作成し、次にさまざまな役割の企業にユーザーを追加することです。は未知の属性 `company_profile_id`を書き込めません
企業プロファイルはアドレスオブジェクトを持っている、と私は新しいコールにフォームをプルアップするとき、私はこのエラーを取得:
company_profile「不明な属性company_profile_id
書き込むことはできません」 - >新しい
<%= form_for(setup_companyProfile(@companyProfile), validate: true, html: { multipart: true }) do |f| %>
<%= f.fields_for :address do |address| %>
<%= render :partial => 'shared/address', :locals => {:f => address} %>
<% end %>
<% end %>
を
user.rb
belongs_to :company_profile
helper.rb
def setup_companyProfile(companyProfile)
if(companyProfile.address.present? == false)
companyProfile.address ||= Address.new
end
companyProfile
end
company_profile.rb
class CompanyProfile < ApplicationRecord
has_many :users
has_one :address
accepts_nested_attributes_for :address
end
company_profile_controller.rb
class CompanyProfileController < ApplicationController
def new
@companyProfile = CompanyProfile.new
end
def edit
@companyProfile = CompanyProfile.find(current_user.company_profile_id)
end
def update
end
def show
end
end
これは、ありがとう! – bralyan