rubyonrailsin

A Ruby and Rails talk

Sunday, March 21, 2010


Re: [Rails] Using ActionMailer on a controller method

by rubyonrailsin 0 comments

Tag


Share this post:
Design Float
StumbleUpon
Reddit

On 21 March 2010 20:03, command0 <justinbrinkerhoff@gmail.com> wrote:
> The problem I am having, is when I try to create a new ticket, I get
> the error:
>
> NoMethodError (undefined method `customer' for nil:NilClass):
>  app/models/ticket_mailer.rb:7:in `newticket'
>  app/controllers/tickets_controller.rb:84:in `create'
>
> Which I know simply put is telling me the customer doesn't exist,
> because customer_id would be nil, so there is no association. But
> there is.

No, it's telling you that the "ticket" variable (at line 7 of
ticket_mailer.rb) is nil, and NilClass objects don't have a "customer"
method.

> class TicketMailer < ActionMailer::Base
>  def newticket(ticket)
>    ticket = @ticket
>    subject    'A new ticket has been created for you'
>    recipients  ticket.customer.email
>    from       'helpdesk@stevenshenager.edu'
>    sent_on    Time.now
>  end

I'd assume the problem is caused by the assignment in the first line
of the method; I'd guess it's meant to read:
@ticket = ticket
..because as it is, it doesn't make much sense to pass in a ticket
parameter and then immediately overwrite it with an instance variable.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment

Subscribe feeds via e-mail

Blog Archive