Reputation: 158
I have this code:
<%= 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 %>
But, the hidden field ":employee", don't send the selected employee, only send if this "f.association" is not hidden.
My controller is default scaffold:
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
I need to send this value of "f.association :employee" but without show in the browser.
Upvotes: 2
Views: 3322
Reputation: 50057
Just send the @employee.id
instead?
Like so
<%= f.input :employee_id, as: :hidden %>
And you can set the value immediately in your controller, e.g.
def new
@uniform = Uniform.new
@uniform.employee = @employee
...
Upvotes: 2