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