Created
February 29, 2012 21:56
-
-
Save doncote/1944754 to your computer and use it in GitHub Desktop.
habtm_checkboxes for twitter bootstrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks!