Showing app/views/posts/_post.html.erb where line #4 raised:
undefined method `name' for nil:NilClass
Extracted source (around line #4):
1: <p>
2: <b>Post Content:</b>
3: <%=h post.content %> by
4: <%=h post.author.name %>
5: </p>
Here is my posts model:
class Post < ActiveRecord::Base
belongs_to :board
belongs_to :author, :class_name => "User"
end
The weird thing is, if I comment out post.author.name, it works. And.... I tried it in the console, it works fine:
>> post
=> #<Post id: 1, content: "trying", user_id: 2, created_at: "2010-06-22 04:24:53", updated_at: "2010-06-22 04:24:53">
>> post.author
=> #<User id: 2, login: "[email protected]", name: "test1",....
>> post.author.name
=> "test1"
In fact, if I change post.author.name to post.user_id, it displays the correct id (which is 2)....
What is the problem??
Thanks a lot.