2016-09-14 5 views
0

私は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 

答えて

0

あなたは会社プロファイルモデルからhas_oneを使用して... RailsはAddressモデルにbelongs_to :company_profileがあるように期待しています。 ..このbelongs_toaddressesテーブルにcompany_profile_idという列が必要です。それはありますか?そうでない場合は、追加するマイグレーションを作成する必要があります。

+1

これは、ありがとう! – bralyan

関連する問題