raphael_turtle
raphael_turtle

Reputation: 7314

Rails collection_check_boxes, Using two labels with one from an association

I have an Available model with a date attribute, I also have a User model. A user has_many :availables and available belongs_to :user.

@dates is a collection of Available records. In the form I want to show both the date and the associated user name for that record. What I currently have is working though I can't click name to select the checkbox, is there a proper way to do this and style it via bootstrap?

    = f.collection_check_boxes :col_ids, @dates, :id, :date do |b|

      .field
        .checkbox-inline
           = b.check_box
           = b.label
           = b.object.user.name

Upvotes: 0

Views: 344

Answers (1)

max
max

Reputation: 101811

What you want is a checkbox which is inside the label tag.

= f.collection_check_boxes :col_ids, @dates, :id, :date do |b|
  .field
    .checkbox-inline
      = b.label do
        = b.check_box
        = b.text
        = b.object.user.name

On a side note your model should be named Availablity which is a noun. Not the adverb form available (availables is not an english word).

A person may be available, but has many availabilities.

availability

plural avail·abil·i·ties

  1. the quality or state of being available
  2. an available person or thing

http://www.merriam-webster.com/dictionary/availability

This is not a big deal but can give english speakers are real WTF moment when trying to understand your code.

Upvotes: 1

Related Questions