Search code examples
ruby-on-railscheckboxnomethoderror

Using checkboxes in rails


I've never used checkboxes in rails before and can't figure out what I'm doing wrong. When I try to load my page, I get an error that says NoMethodError in Dplans#show, undefined method "merge" for "Art":String

Here is the code for my checkbox form on the Dplans show page:

<%= form_for @dplan, :url=>{ :action=>"update_distribs" } do |f| %>
<%= f.check_box :Art, 'Art' %> <b>Art</b> <br/>
<%= f.check_box :Lit, 'Lit' %> <b>Lit</b> <br/> <br/>

<div class="actions">
  <%= f.submit "Save" %>
</div>
  <% end %>

Art and Lit are both strings and are attr_accessible in dplan. Thanks for your help!


Solution

  • The second parameter to FormBuilder.check_box is a hash of HTML options.. The string you specified is not necessary. Try this instead:

    <%= f.check_box :Art %> <b>Art</b> <br/>
    <%= f.check_box :Lit %> <b>Lit</b> <br/> <br/