Hiding Checkbox & Assigning Value - Ruby on Rails - Easy Question

forms, ruby, ruby-on-rails

Solution

You can certainly do this, but if all you want is to set a parameter without displaying a field, what you probably want instead is a hidden field:

<%= f.hidden_field :vote, :value => '1' %>

If you really do want a hidden checkbox (maybe so you can optionally display it later using javascript?), you can do it like this:

<%= f.check_box :vote, :checked => true, :style => 'visibility: hidden' %>

Problem

I am trying to hide a checkbox and assign a default value of 1 such that the submit button only shows. Here is my form. Just wondering as the proper format as I am new to rails. I think you can do this with helpers but was wondering if I can just include it in the form. Here is the form: ``` <% remote_form_for [@post, Vote.new] do |f| %> <p> <%= f.label :vote %> <%= f.check_box :vote %> </p> <%= f.submit "Vote" %> ```

Original source