我有这段代码:
<%= simple_form_for(@uniform) do |f| %>
<%= f.error_notification %>
<%= f.association :employee, as: :hidden, selected: @employee %>
<%= f.association :piece %>
<%= f.button :submit, "Add new piece" %>
<% end %>
但是,隐藏的字段&#34;:员工&#34;,不发送所选择的员工,只有在这个&#34; f.association&#34;没有隐藏。
我的控制器是默认支架:
def create
@uniform = Uniform.new(uniform_params)
respond_to do |format|
if @uniform.save
format.html { redirect_to @uniform, notice: 'Uniform was successfully created.' }
else
format.html { render action: 'new' }
end
end
end
我需要发送&#34; f.association:employee&#34;的这个值。但没有在浏览器中显示。
答案 0 :(得分:2)
只需发送@employee.id
即可?
喜欢这样
<%= f.input :employee_id, as: :hidden %>
您可以立即在控制器中设置值,例如
def new
@uniform = Uniform.new
@uniform.employee = @employee
...