Reputation: 14227
I'm trying to pass association values as hidden field in simple form
so same functionality like when you do ...
= simple form for @document do |f|
= f.association :clients
...but will generate hidden field insted
I'm trying to do it as this
= f.association :clients, as: hidden
but that wont work obviously
only thing that works for me is
%input{ name: 'document[client_ids][]', value: '1'}
%input{ name: 'document[client_ids][]', value: '2'}
%input{ name: 'document[client_ids][]', value: '3'}
Upvotes: 1
Views: 6429
Reputation: 959
An array is sent on submit from associations in simple form. The following will allow for this using a hidden field:
<%= f.hidden_field('client_ids][', value: "some value") %>
(Note: The reversed brackets are important)
Upvotes: 1
Reputation: 96454
Maybe
=f.hidden_field :client_id, :value => "some value"
but I think you'd be better of explaining the bigger picture and then we can suggest a suitable rails answer for you. In most cases using hidden fields is a sign that something should be done a better way.
Upvotes: 2
Reputation: 24617
I think
<%= f.association :clients, input_html: { hidden: true } %>
should work.
Upvotes: 0