5
こんにちはテキストフィールドに入力したすべてのメールコンマアドレスにメールを送信します。私はそうするために次のコントローラを持っています。複数のカンマ区切りのメールアドレスにメールを送信
def send_invites #friend invites
@emails_txt = params[:emails_txt]
@emails = @emails_txt.split(/\s*,\s*/)
@ve = []
@emails.each do |email|
if email =~ /\b[A-Z0-9._%a-z-][email protected](?:[A-Z0-9a-z-]+.)+[A-Za-z]{2,4}\z/
@ve << email
end
end
@all_ok = true
@errors = []
@ve.each do |email|
@invitation = Invitation.new
@invitation.sender = current_user
@invitation.recipient_email = email
if @invitation.save
UserMailer.invitation_notification(current_user, @invitation, new_user_registration_url+"/#{@invitation.token}").deliver
else
@all_ok = "false"
@errors << @invitation.errors
end
end
end
それは素晴らしい仕事をしていたが、
NoMethodError in InvitationsController#send_invites
undefined method `username' for nil:NilClass
を次のように問題が私を助けてくださいいただきました今では、エラーを与えています。ありがとうございます
お返事ありがとうございます。私はあなたが正しいと思います。電子メールアドレスのリストを取得したときにサインアウトしています。なぜなら、 'current_user'がnilにならない理由です。 –
私はレールのform_forタグの代わりに通常のhtmlフォームを使用していたからです。 form_forタグを使用すると、フォーム内にアプリケーションのトークンが自動的に含まれます。これはセキュリティ上の懸念から非常に重要です。 –