Wednesday, 15 June 2011

ruby on rails - Check_box_tag not displaying labels properly -



ruby on rails - Check_box_tag not displaying labels properly -

everything posting correctly, not see labels in checkboxes, blanks. form looks this:

<%= form_for @itemrecord |f| %> <div class="col-xs-12"> <p><b>items people asking for</b></p> </div> <% @wishlist.each |category, list| %> <div class="col-xs-2"> <div class="form-group box"> <h5> <%="#{category}"%> </h5> <% list.each |thing| %> <%= check_box_tag ":item_name[]", "#{thing}" %> </br> <% end %> </div> </div> <% end %> <%= f.submit "go!", class: "btn btn-primary btn-large btn-block" %> </div> <% end %>

what's happening wishlist hash of categories , items within categories set in controller, , called multiple form builders build checkboxes. challenge right in current implementation, checkboxes params passed through (fyi controller code @ bottom), beside each checkbox, there no text shows thing (i.e., no label people know they're checking.

here's html generated 1 checkbox (it's same checkboxes)

basically, need create value label.

fyi what's happening every item checked, record beingness created. here's controller code:

def create items_to_be_saved = [] inventory_params.each |i| items_to_be_saved << ({ :signup_id => signup.find_by_email(session[:signup_email]).id, :item_name => }) end if inventory.create items_to_be_saved flash[:success] = "thanks!" redirect_to root_path else render new_inventory_path end end def inventory_params params.require(":item_name") end

in code:

<%= check_box_tag ":item_name[]", "#{thing}" %>

second parameter check_box_tag not label value, value goes controller in parameters. if wan't display label within checkbox need phone call label_tag in view:

= label_tag ':item_name[]', thing = check_box_tag ':item_name[]'

but should check simple_form gem allows render checkboxes in much cleaner way:

f.input :field, as: :boolean, inline_label: 'label'

ruby-on-rails forms checkbox form-helpers

No comments:

Post a Comment