0
在这里,我通过params来定义接收者。
如果我想将消息发送给所有已经同时确认的用户,该怎么办?
我该怎么写?如何将消息发送给所有用户?
任何人有任何想法?
控制器
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
谢谢:)请让我试试:) – HUSTEN 2013-03-05 15:24:50
它不应该是'users.each做|收件人|'?? – HUSTEN 2013-03-05 15:31:37
我的坏,改变了一点 – Intrepidd 2013-03-05 15:32:58