作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在提交表单时将选择标签中的选定值插入到数据库中。
问题是所有值都是从 select 标签中选择的,但是当我提交表单时,只有第一个值总是插入到数据库中,而不是选择的值。
我的_form.html.erb文件
<div class="form-group">
<label class="control-label">Requirement Type</label>
<div class="input-group"> <span class="input-group-addon"> <i class="fa fa-globe"></i> </span>
<%= f.select :job_types, Settings.job_types_for_job_posting.to_a.map { |w| [w.humanize, w] }, {}, class: "form-control" %>
</div>
</div>
我的枚举在setting.yml文件中定义
job_types_for_job_posting: [Contract, Permanent, On Demand, Internal]
我的jobs_controller.rb文件是
def create
@job = current_user.job_postings.build(params_value)
respond_to do |format|
if @job.save
add_or_update_skills
format.json { render json: { result: true } }
format.html { redirect_to root_path, notice: 'Job is posted successfully' }
else
format.json { render json: { result: false } }
format.html { render :new }
end
end
end
params.require(:job_posting).permit(:title, :description, :salary_from, :salary_to, :experience, :experienceto,
:expected,:key,:sourcing,:client_id, :job_assignment,:status, :no_of_opening, :location, :designation, :responsibilities, :job_skills, :industry_id, :functional_area_id, :role_category_id, :job_role_id, :job_types)
end
当我准备新工作时,每次只插入“契约(Contract)”表示 0。任何人都可以告诉我,我哪里错了......
最佳答案
(没有测试)我认为你的行应该是:
<%= f.select(:job_types, Settings.job_types_for_job_posting.to_a.collect.with_index { |w, i| [w.humanize, i] }, {}, class: "form-control") %>
数组的索引应该是你的值,对吧?
关于mysql - 如何从 f.select in rails 中插入选定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40800099/
我是一名优秀的程序员,十分优秀!