mikeglaz (11) [Avatar] Offline
#1
I'm getting the error produced by this line: Created by <%= @ticket.user.email %>

The error is undefined method `email' for nil:NilClass. The text doesn't specify how to alter my code in order to get rid of this error.

thanks,
mike
ryanbigg (423) [Avatar] Offline
#2
Re: Chapter 6.5.2
It looks like you're not associating a ticket with a user. Can you put your application on GitHub so I can check it out please?
mikeglaz (11) [Avatar] Offline
#3
Re: Chapter 6.5.2
Yeah, I think I had the tickets created before the user was created.
mikeglaz (11) [Avatar] Offline
#4
Re: Chapter 6.5.2
Ok, I just figured out what I did to fix it. The text says to change this line:


@ticket = @project.tickets.build(params[:ticket])

to this inside the TicketsController create action:

@ticket = @project.tickets.build(params[:ticket].merge!(:user => current_user))

but someone on StackOverflow suggested I place these 2 lines instead:

@ticket = @project.tickets.build(params[:ticket])
@ticket.user = current_user

and it fixed the problem of having User returning nil.
I'm really not sure what the merge! thing is doing...

mike
ryanbigg (423) [Avatar] Offline
#5
Re: Chapter 6.5.2
Ah, yeah that would be necessary now in Rails 3.2 due to the mass-assignment changes. This has been fixed this in the second edition now.