开发者

Sending Emails to multiple comma separated email addresses

Hi I want to send emails to all the email comma addresses entered in text field. I have following controller for doing so.

 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-]+@(?:[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

It was working fine but now it is giving error as follows

NoMethodError in InvitationsController#send_invites 
undefined method `username' for nil:Nil开发者_运维百科Class

whats the problem please help me. Thank you


It looks like you are perhaps referencing a nil object in your email view.

I would look in your view for the UserMailer#invitation_controller action and see where you reference username.

Then, once you found that, trace back the object and find out why its nil, then add some testing around that (i.e. if current_user.nil? ...).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜