English 中文(简体)
铁路图人中的光谱错误:未界定的当地变数或方法`静态'网页_index_path
原标题:rspec error during Rails Tutorial : undefined local variable or method `static_pages_index_path

I m followind the Rails Tutorial but have a problem in section 3.2.1, just before figure 3.6. When running

$ bundle exec rspec spec/requests/static_pages_spec.rb

我的失败

Failures:
  1) StaticPages GET /static_pages works! (now write some real specs)
     Failure/Error: get static_pages_index_path
     NameError:
       undefined local variable or method `static_pages_index_path  for # <RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007fe7592b33b8>
     # ./spec/requests/static_pages_spec.rb:7:in `block (3 levels) in <top (required)>     
Finished in 0.00454 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/requests/static_pages_spec.rb:5 # StaticPages GET /static_pages works! (now write some real specs)

档案:

spec/requests/static_pages_spec.rb

require  spec_helper 
describe "Static pages" do
  describe "Home page" do
    it "should have the content  Sample App " do
      visit  /static_pages/home 
      page.should have_content( Sample App )
    end
  end
end

app/controllers/static_pages_controller.rb

class StaticPagesController < ApplicationController
  def home
  end
  def help
  end
end

app/views/static_pages/home.html.erb

<h1>Sample App</h1>
<p>
  This is the home page for the
  <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
  sample application.
</p>

config/routes.rb

SecondApp::Application.routes.draw do
  get "static_pages/home"
  get "static_pages/help"
end

Gemfile

source  https://rubygems.org 
gem  rails ,  3.2.3 
group :development do
  gem  sqlite3 ,  1.3.5 
  gem  rspec-rails ,  2.9.0 
  gem  guard-rspec ,  0.5.5 
end
group :assets do
  gem  sass-rails ,    3.2.4 
  gem  coffee-rails ,  3.2.2 
  gem  uglifier ,  1.2.3 
end
gem  jquery-rails ,  2.0.0 
group :test do
  gem  rspec-rails ,  2.9.0 
  gem  capybara ,  1.1.2 
  gem  growl ,  1.0.3 
end
group :production do
  gem  pg ,  0.12.2 
end

任何关于我有错的想法?

问题回答

我也面临这个问题;辅导似乎忽略了一个步骤。

www.un.org/chinese/sc/presidency.asp

get static_pages_index_path

......应当改为:

get static_pages_home_path

这是因为在<编码>上没有<代码>/index方法> 。 改为home

不过,我审查了你的代码,看来是static_pages_spec.rb。 档案与教学材料不相符,但我猜测你从另一个地方复制该守则? I do not see static_pages_index_path 除你看来有奇怪的ole误案文外,在任何地方。

这是我的<代码>static_pagespec.rb全文(本阶段),经过测试:

require  spec_helper 

describe "StaticPages" do
  describe "GET /static_pages" do
    it "works! (now write some real specs)" do
      # Run the generator again with the --webrat flag if you want to use webrat methods/matchers
      get static_pages_home_path
      response.status.should be(200)
    end
  end
end

之后,理论(在Listing 3.12)将这一步骤推向后,修改了static_pages_spec.rb,尽管是为了明确建议这一改动。 这使我的法典变得无关紧要,但希望它解释你的错误。

更仔细地看<代码>spec/requests/static_pages_spec.rb。 请确保您删除<代码>各点静电页_index_path。

阁下 页: 1

我也存在同样的问题,我以以下方式说明了这个问题。 我也是一个新班子(第一个Sack Overflow post... nervous),因此我没有jar倒:

我之所以发现这一错误,是因为我没有制造导师名单3.4所描述的静态页面控制器(我认为我删除了它所描述的与实践指挥的相隔,而实践指挥员名单是3.4,教你如何做hem,删除。 检查你是否有固定页面控制器的方法是:

<代码>sample_app/ Controllers/,因此,我只收到申请_ Controller.rb文档,没有static_pages_ Controller.rb

So you have to run the rails generate controller StaticPages home help --no-test-framework command and get that controller in there.

您可以通过访问<条码>:3000/static_pages/home来重复工作,看看是否有实际的东西。

然后,每部辅导员,home.html.erb文档,然后核对static_pages/home,看看它是否实际说“Sample App”。

If static_pages/home actually says "Sample App" and the test is still a failure when you run it, then only God can help you. Or maybe someone else on Stack Overflow. Good luck.

您是否删除了公共/指数? 这可能造成问题。

当你把“Conig.include Capybara:DSL”添入RSpec助手档案的底部时,你可能会忘记拯救该网页。 这样做的办法是将指挥官+钥匙放在一起。 有时,如果你第一次不工作,重新启用铁路服务器,也是好的想法。

问题在于,你正在试图掌握一个实际上还没有奏效的老板。 辅导员告诉你,用这个字眼取代:

it "should have the content  Sample App " do
  visit  /static_pages/home 
  page.should have_content( Sample App )
end

请注意,报告“内容”、“目标”等等。

之所以出现这种情况是因为光谱生成器( 铁路产生一体化-测试静态_pages)假设,有有效的无害环境技术资源,包括_index_path,但该监管机构的情况根本不是这样。

我也面临同样的问题。 当你编辑<代码>static_pagespec.rb时,你会像你那样打上这一指挥(列入名单3.9)。

<editor name> static_pages_spec.rb

而你们必须打字

<editor name> spec/requests/static_pages_spec.rb

这肯定会解决你的问题。





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签