我有一个作业模型,其属性为:rush,这是一个布尔值。我使用check_box表单助手来切换:rush。
复选框表单元素:
<%= check_box_tag(:rush) %>
<%= label_tag(:rush, "Rush?") %>我的强参数方法:
def job_params
params.require(:job).permit(:recipient, :age, :ethnicity, :gender, :height, :weight, :hair, :eyes, :other_info, :instructions, :user_id, :company_id, :case_id, :rush, addresses_attributes:[:id, :label, :addy, :apt, :city, :state, :zip ] )
end创建操作:
def create
@job = Job.new(job_params)
@job.user_id = current_user.id
if @job.save
redirect_to current_user
else
render 'new'
end
end当表单提交时,它不会保存:rush -所有其他属性--包括嵌套属性--都保存得很好。我是不是漏掉了什么?
发布于 2014-05-30 23:10:13
因为你的职能是:
params.require(:job).permit(:recipient, :age, :ethnicity, :gender, :height, :weight, :hair, :eyes, :other_info, :instructions, :user_id, :company_id, :case_id, :rush, addresses_attributes:[:id, :label, :addy, :apt, :city, :state, :zip ] )然后,您将期望:rush嵌套在:job中,即params[:job][:rush]。因此,您应该将其嵌套到html中的job属性中:
<%= check_box_tag("job[rush]") %>这应该能行。
https://stackoverflow.com/questions/23964609
复制相似问题