title: RoR - dynamic dropdown with checkboxes
body: <p>I am looking to implement a dynamic dropdown with checkboxes in it so the sender of a message can choose multiple receivers.</p>
  
  <p>Currently I just have a list of recipients under the message textarea.</p>
  
  <p>_recipients.html.erb:</p>
  
  <pre><code>&lt;% @recipients.each do |user| %&gt;
    &lt;label for="user&lt;%= user.id %&gt;" &gt;
      &lt;span class="list-group-item"&gt;&lt;%= user.full_name %&gt;&lt;/span&gt;
      &lt;%= check_box_tag "message[user_tokens][]", user.id, @message.users.include?(user), id: "user#(user.id)", class: "form-control" %&gt;
    &lt;/label&gt;
  </code></pre>
  
  <p>User.rb:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
  
    rolify
    # Include default devise modules. Others available are:
    # :confirmable, :lockable, :timeoutable and :omniauthable
    devise :database_authenticatable, :registerable,
           :recoverable, :rememberable, :trackable, :validatable
  
    validates :full_name, presence:true,
              length: {minimum: 4 }
  
    has_many :messages, foreign_key: :sender_id
    has_many :notes
    has_many :homeworks
    has_many :hw_comments
    belongs_to :classmodule
    belongs_to :student
  </code></pre>
  
  <p>recipient.rb:</p>
  
  <pre><code>class Recipient &lt; ActiveRecord::Base
      belongs_to :message
      belongs_to :user
  
      validates :user_id, presence: true
  end
  </code></pre>
  
  <p>messages_controller.rb:</p>
  
  <pre><code>class MessagesController &lt; ApplicationController
      before_action :authenticate_user!
  
      def new
          @message = Message.new
          @recipients = User.all 
          @recipients = @recipients.page(params[:page]).per(8)
      end
  
      def create
          @message = current_user.messages.build(message_params)
  
          if @message.save
              flash[:success] = "Message sent"
              redirect_to messages_path
          else
              flash[:alert] = "Something went wrong"
              render :new
          end
      end
  
      def index
          @messages = Recipient.where(:user_id =&gt; current_user.id).order('created_at DESC')
      end
  
      private
      def message_params
          params.require(:message).permit(:title, :body, :sender_id, user_tokens: [])
      end 
  end
  </code></pre>
  
  <p>Is it possible to get the checkboxs and names in to a dropdown with collection_select for example? Happy to provide more code if required. Thanks.</p>