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 << “#{user.name}”
end
s.html_safe
end

On 15 January 2015 at 04:12, David W. [email protected]
wrote:

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 L. wrote in post #1166693:

On 15 January 2015 at 04:12, David W. [email protected]
wrote:

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 << “#{user.username}”
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?

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


Daniel L.