我很确定我的问题比我在 stackoverflow 上看到的 has_many 嵌套表单问题要复杂一些
我有两个模型,一个是 company.rb,另一个是 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 的空作业。
我已经为此工作了两天,有人可以帮助我吗?我在表单上尝试了 fields_for,但没有发布任何内容?
这是我的日志
Processing by JobsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"9P+tEDamlP9+jEHU31gL93hc4GyhXTZoe3zoMopKHa0=", "job"=>{"title"=>"software", "description"=>"make software"}, "commit"=>"Create Job"}