title: Rails: passing params hash to model
body: <p>I have a user-to-user messaging system. I'm trying to pass an array of user ids to a <code>ConversationUser</code> (join table) model which would then create multiple <code>conversation_users</code> from each individual <code>user.id</code>. The two fields in <code>ConversationUser</code> are <code>conversation_id</code> and <code>user_id</code>. I'm able to initialize a single conversation user because the new <code>conversation_id</code> is being passed along to the model, but for some reason, the hash of user ids is not getting to my model. I'm getting a <code>Validation failed: User can't be blank</code></p>
  
  <p>My conversation/new view for capturing the user_ids:</p>
  
  <pre><code>&lt;%= check_box_tag "conversation_user[recipient][]", user.id %&gt; &lt;%= user.name %&gt;&lt;br /&gt;
  </code></pre>
  
  <p>I know this is working because part of my params that I'm receiving back are:</p>
  
  <pre><code>"conversation_user"=&gt;{"recipient"=&gt;["9", "10"]}
  </code></pre>
  
  <p>The essentials of my Rails 4 controller &amp; strong params:</p>
  
  <pre><code>class ConversationsController &lt; ApplicationController
    def new
      @user = User.find(params[:user_id])
      @conversation = @user.conversation_users.build
      @conversation.build_conversation.messages.build
    end
  
    def create
      @conv = Conversation.create!
      @conversation = @conv.conversation_users.create!(conversation_user_params)
    end
  
    def conversation_user_params
      params.require(:conversation_user).permit(recipient: [])
    end
  </code></pre>
  
  <p>The essentials of my ConversationUser model:</p>
  
  <pre><code>class ConversationUser &lt; ActiveRecord::Base
    attr_accessor :recipient
  
    before_create :acquire_conversation
  
    validates :user_id, :conversation_id, presence: true 
  
    def acquire_conversation
      unless recipient.blank?
        recipient.each do |u|
          ConversationUser.create(user_id: u, conversation: conversation)
        end
      end
    end
  end
  </code></pre>
  
  <p>I think the problem is somewhere in my controller's <code>conversation_user_params</code>. But it also might be in the model's <code>before_create</code> method. I've been trying to fix this problem for a day now, with lots of debugging with no success. If anyone can be of assistance, I thank you in advance.</p>