Search code examples
jqueryruby-on-railsformshidden

Rails Form, How to set value of hidden field with jquery


in my rails application in a view, i have some input box

....
 <%= form.label :object_id %>
 <input type="text" id="bla" disabled="disabled">
 <%= form.hidden_field :object_id, id: :_id %>
.... 

with my Jquery script i tryed to set the value of the hidden field and it sets the right value, but when i submit the form to save it save something like that:

# < something :0x007f2331b74408>

Why? Can anyone help me ?


Solution

  • The hidden_field method has the following signature:

    hidden_field(object_name, method, options = {})
    

    Try setting it as follows:

    <%= f.hidden_field 'object_id', :value => params[:object_id] %>
    

    Right now, the value of the field is set to a reference of a object rather than the value.