Ann
Ann

Reputation: 139

How to add check_box_tag for form builders?

I am building a form for pets that have illness. I am getting an error saying: undefined method check_box_tag for # This is how my tag looks for form builder. I prefer a check_box_tag instead of radio button. How do I use a check_box_tag for form builders?

      <p><%= form_for(@pets) do |f| %>
      <% @checkups.each do |checkup| %>
      <td><%= checkup.illness %></td>
      <td><%= @checkup.illnessname %></td>
      <%= f.check_box_tag :response, "a" %>
        <!-- many more illness options below -->

     <%end%>
     <%=f.submit%>
     <%end%>

Upvotes: 0

Views: 225

Answers (1)

Bryan Oemar
Bryan Oemar

Reputation: 926

Don't use the form_builder 'f' if you'd like to use the '_tag' version. Just use check_box_tag without accessing it from the form builder.

So this will become:

 <%= check_box_tag :response, "a" %>

Or if the :response is an accessible field on @pets, you should do:

 <%= f.check_box :response, {}, "a" %>

Notice the different API's (method signatures) for both methods.

Also for reference, you should see: http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.htm

Upvotes: 1

Related Questions