Question

I have a form that saves the parameters into a CSV, but I also want to send the parameters within an email, always to the same address. I currently have the following:

mailer

def notification_email(partner)

  @partner = partner   

  mail(:subject => "Partner Application", :to => "example@example.com")

end

controller

partner = Hash.new

params.each do |k, v|

  partner[k] = v

end

UserMailer.notification_email(@partner).deliver
format.html { redirect_to :controller => 'general', :action => 'partnerApplyThanks'}
format.json { render :json => @partner, :status => :created, :location => @partner }

mailer view

<table>
    <tr>
        <td>Name</td>
        <td><%= @partner[:first_name] %></td>
    </tr>

</table>

But I get this error:

undefined method '[]' for nil:NilClass

referring to this part of the mailer view:

<td><%= @partner[:first_name] %></td>
Was it helpful?

Solution

Ended up with this:

mailer

def notification_email(params)

@partner = params

mail(:to => "example@example.com", :subject => "Partner Application" )

end

controller

UserMailer.notification_email(params).deliver

mailer view

<td>Forename:</td><td> <%= @partner[:first_name]%></td>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top