On Tuesday, October 2, 2012 1:36:04 AM UTC-7, desbest wrote:

>
>    @notification = Post.where(:noti_recipient => user.id, :noti_read => 
> 'no').order(:datetimenumber).last
>
> This looks innocent enough, fetching the last row of a query.
>
> But watch what happens when I try to use foreign keys in my template.
>
> #{@notification.user_id.username}
>
> undefined method `username' for 2:Fixnum
>
> However #{@notification.user_id} works fine.
>
> What is going on?
>

My guess is that user_id is a Fixnum, and you have not defined a 
Fixnum#username method.

You probably want:

  #{@notification.user.username}

assuming that you have created the appropriate association.

Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sequel-talk/-/Tjpg9RPutSYJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to