Skip to content

Instantly share code, notes, and snippets.

@doncote
Created February 29, 2012 21:56
Show Gist options
  • Save doncote/1944754 to your computer and use it in GitHub Desktop.
Save doncote/1944754 to your computer and use it in GitHub Desktop.
habtm_checkboxes for twitter bootstrap
def habtm_checkboxes(obj, column, assignment_objects, assignment_object_display_column, label_css_class)
obj_to_s = obj.class.to_s.split("::").last.underscore
field_name = "#{obj_to_s}[#{column}][]"
html = hidden_field_tag(field_name, "")
html += "\n"
assignment_objects.each do |assignment_obj|
cbx_id = "#{obj_to_s}_#{column}_#{assignment_obj.id}"
cbx = check_box_tag field_name, assignment_obj.id, obj.send(column).include?(assignment_obj.id), :id => cbx_id
html += label_tag cbx_id, h(assignment_obj.send(assignment_object_display_column)) + " " + h(cbx), :class => label_css_class + ' checkbox'
html += "\n"
end
html
end
@mattslay
Copy link

I've used this, and it works fine. Great work!!

@doncote
Copy link
Author

doncote commented Apr 21, 2012

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment