rmagnum2002
rmagnum2002

Reputation: 11421

rails 3 mailer_action

Any idea how can I send my model params to mail?

Here is the problem: I have a cardealler application and in car.show page I made a link called "Send email request"

<%= link_to 'Send email request',  send_to_mail_car_path(@car) %>

in cars_controller:

def send_to_mail
    CarMailer.request_email(@car).deliver
    @car = Car.find(params[:id])
    @search = Car.search(params[:search])
    redirect_to @car, :notice  => "Notification sent."
  end

that is working, I recieve mails from clients(that would be me, cause tha app it's in development stage).. but I recieve this mail as long it's only plain text in those 2 files:

request_email.html.erb and request_email.text.erb

when I am trying to add some car data it gives me errors.. so if I'll write in these files:

<%= @car.id %> so I can view the id of car in mail, instead of id I have this error on my screen:

Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id

4:     <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
5:   </head>
6:   <body>
7:     <h1> <%= @car.id %></h1>
8:     <p>

in the user.confirm_registration tutorial is used also like this <%= user.name %> and I managed to get the user name in mail.. Why I can't see my car in my app then?

Any help will be apreciated. Some tutorials may be.. thanks.

Upvotes: 0

Views: 131

Answers (1)

yfeldblum
yfeldblum

Reputation: 65445

The problem is here:

CarMailer.request_email(@car).deliver
@car = Car.find(params[:id])

You have to assign to @car before you can use it.

@car = Car.find(params[:id])
CarMailer.request_email(@car).deliver

Upvotes: 1

Related Questions