0
我有這樣的錯誤,當我'測試我控制器Rails的未定義的方法 'FULL_NAME'
ActionView::Template::Error: undefined method `full_name' for nil:NilClass
我的測試:
class PostsControllerTest < ActionController::TestCase
include Devise::TestHelpers
setup do
@post = Post.create!(title: "my title", content: "bla bla bla")
user = User.create!(email: "[email protected]", first_name: "name", last_name: "surename",
password: "password", password_confirmation: "password")
sign_in user
end
test "should show post" do
get :show, id: @post
assert_response :success
end
FULL_NAME方法模型:
def full_name
"#{first_name} #{last_name}"
end
和我的看法:
Wrote by
= @post.user.full_name
感謝您的幫助
嘿認爲thier是你的職位多數民衆贊成在沒有用戶爲什麼它返回這個例外 –