Ruby on rails RSpec失败:未定义的方法`name';零级:零级
我正在浏览一本书(Rails 4在v14 MEAP中运行),在运行我的规范时遇到了一个错误:Ruby on rails RSpec失败:未定义的方法`name';零级:零级,ruby-on-rails,rspec,Ruby On Rails,Rspec,我正在浏览一本书(Rails 4在v14 MEAP中运行),在运行我的规范时遇到了一个错误: Failures: 1) Creating Projects can create a project Failure/Error: click_button 'Create Project' ActionView::Template::Error: undefined method `name' for nil:NilClass # ./app/vie
Failures:
1) Creating Projects can create a project
Failure/Error: click_button 'Create Project'
ActionView::Template::Error:
undefined method `name' for nil:NilClass
# ./app/views/projects/show.html.erb:1:in `_app_views_projects_show_html_erb__1338549725163946383_70209940313300'
# ./spec/features/creating_projects_spec.rb:11:in `block (2 levels) in <top (required)>'
Finished in 0.23155 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/features/creating_projects_spec.rb:4 # Creating Projects can create a project
我对该项目的回购协议在
非常感谢任何指导。在控制器的
show
方法中,设置实例变量@projects
(复数)
在show
视图中,使用实例变量@project
(单数)
非常感谢。我以为我忽略了一些简单的事情。一旦我可以验证,我会将此标记为已接受的答案
Failure/Error: expect(page).to have_content('Project has been created.')
expected there to be text "Project has been created." in "TextMate 2"
def show
@projects = Project.find(params[:id])
end
<h2><%= @project.name %></h2>
def show
@project = Project.find(params[:id]) # @project instead of @projects
end