views:

464

answers:

3

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" %>
A: 

If you just want to pass the value along, use a hidden field

<% remote_form_for [@post, Vote.new] do |f| %>
  <%= f.hidden_field_tag 'vote', '1' %>
  <%= f.submit "Vote" %>
<% end %>
Carlos Lima
A: 

You could use CSS to hide the checkbox:

<%= f.check_box_tag :vote, 1, true, :style => "display: none;" %>

But if you just want to pass a value you can just use a hidden field:

<%= f.hidden_field_tag, :vote, 1 %>
Jordan
+1  A: 

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' %>
John Hyland