私の問題は、stackoverflow で見た has_many ネストされたフォームの質問よりも少し複雑であると確信しています。
2 つのモデルがあります。1 つは company.rb で、もう 1 つは job.rb です。
会社.rb
has_many :jobs
accepts_nested_attributes_for :jobs, allow_destroy: true
attr_accessible :jobs_attributes
job.rbにはこれがあります
belongs_to :company
私の会社のコントローラーにはこれがあります
def new
@company = current_company.jobs.new
end
def create
#the actual create process where the params from the forms got sent here
@company = current_company.jobs.new(params[:company])
end
認証中の企業向けのデバイスを持っているので、現在ログインしている企業向けにジョブを作成したい
これが私のフォームです
<%= simple_form_for @company do |f| %>
<%= f.input :title %>
<%= f.input :description %>
<%= f.button :submit %>
<% end %>
ジョブのすべてのエントリが作成されていますが、値が渡されていませんか? レコードにも company_id がない空のジョブが記録されています。
私はこれに 2 日間取り組んできましたが、誰か助けてくれませんか? フォームで fields_for を試しましたが、何も投稿されませんか?
これは私のログにあります
Processing by JobsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"9P+tEDamlP9+jEHU31gL93hc4GyhXTZoe3zoMopKHa0=", "job"=>{"title"=>"software", "description"=>"make software"}, "commit"=>"Create Job"}