在这里,我通过参数定义收件人。
如果我想一次将消息发送给所有已经确认的用户怎么办?
我该怎么写?
有人有什么想法吗?
控制器
recipient = User.find_by_username(params[:messages][:recipient])
if recipient.confirmed_at.nil?
redirect_to messages_sent_path
flash[:notice] = "This user hasn't confirmed yet!"
return
end
params[:messages][:subject] = 'no subject' if params[:messages][:subject].blank?
subject = params[:messages][:subject]
body = params[:messages][:body]
if current_user != recipient
current_user.send_message(recipient, body, subject)
redirect_to :controller => 'messages', :action => 'sent'
flash[:notice] = "Sent!"
else
redirect_to :controller => 'messages', :action => 'received'
flash[:notice] = "Cannot send to yourself!"
end