Add multiple user support for a function

These two functions below work perfectly for end to end normal user
interaction. But, I need help giving line 2 of the code "recipients =
User.where(id: params['recipients']) multiple user support. As in allow
User model to interact with BizUser model.

def create
    recipients = User.where(id: params['recipients'])
    conversation = current_user.send_message(recipients,
params[:message][:body], params[:message][:subject]).conversation
    flash[:success] = "Message has been sent!"
    redirect_to conversation_path(conversation)
  end

def recipients_options
    s = ''
    User.all.each do |user|
      s << "<option value='#{user.id}'
data-img-src='#{gravatar_image_url(user.email, size:
50)}'>#{user.name}</option>"
    end
    s.html_safe
  end

These two functions below work perfectly for end to end normal user
interaction. But, I need help giving line 2 of the code "recipients =
User.where(id: params['recipients']) multiple user support. As in allow
User model to interact with BizUser model.

What is BizUser?

Colin

Colin Law wrote in post #1166693:

These two functions below work perfectly for end to end normal user
interaction. But, I need help giving line 2 of the code "recipients =
User.where(id: params['recipients']) multiple user support. As in allow
User model to interact with BizUser model.

What is BizUser?

Colin

I got it.

def create
    recipients = User.where(id: params['recipients']) ||
BizUser.where(id: params['recipients'])
    conversation = current_user.send_message(recipients,
params[:message][:body], params[:message][:subject]).conversation
    flash[:success] = "Message has been sent!"
    redirect_to conversations_index_path(conversation)
  end

def recipients_options
    s = ''
    users = User.all + BizUser.all; users.each do |user|
      s << "<option value='#{user.id}'
data-img-src='#{attachment_url(@user, user.email, :profile_avatar,
:fill, 30, 30)}'>#{user.username}</option>"
    end
    s.html_safe
  end

Hi David,

but what if you have a User with id #10 and a BizUser with id #10? I don’t know much more about your app, but why don’t you send an additional param like params[“user_type”], that will provide an “user” or a “biz”? Or why don’t you use a global unique identificator instead of rely on the “id” field? Or why don’t you add an “U” or “B” before the id on your view (on the form, the “recipients” html field) - so at “create” you can dismember the id from the user type and use the correct model?