2013-03-25 42 views
0

当我运行测试我收到此消息(我猜测它通过),但是当我去本地host300我收到我的所有页面上的以下内容:否路线匹配[GET] “/大约”Hartl教程:3.2错误,当我尝试和清理我的代码

我一直停留在此为大约4个小时:(

这是测试报告我received-

C:\网站\ rails_projects \ sample_app> bundle exec rspec spec/requests/static_pages_ spec.rb C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/ac tive_support/dependencies.rb:251:在require': C:/Sites/rails_projects/sample_ap p/app/helpers/application_helper.rb:12: syntax error, unexpected keyword_end, ex pecting $end (SyntaxError) from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport- 3.2.13/lib/active_support/dependencies.rb:251:in块中需要' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport- 3.2.13/lib/active_support/dependencies .rb:236:load_dependency' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport- 3.2.13/lib/active_support/dependencies.rb:251:in需要C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport- 中的' 3.2.13/lib/active_support/dependencies.rb:359:in require_or_load' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport- 3.2.13/lib/active_support/dependencies.rb:313:in depend_on' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport- 3.2.13/lib/active_support/dependencies.rb:225:在require_dependency' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2 .13/lib/abstract_controller/helpers.rb:135:in block in modules_for_helpers' 从C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2 .13/lib/abstract_controller/helpers.rb:131:在map!' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2 .13/lib/abstract_controller/helpers.rb:131:in个modules_for_helpers'选自C :/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2 0.13/LIB/action_controller /金属/ helpers.rb:92:在modules_for_helpers' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2 .13/lib/abstract_controller/helpers.rb:95:in助手” 从C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2 .13/lib/abstract_controller/helpers.rb:159:在default_helper_module!' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2 .13/lib/abstract_controller/helpers.rb:22:in块中继承' from C:/ RailsInstaller/Ruby1.9.3/lib/ruby​​/gems/1.9.1/gems/actionpack-3.2 .13/lib/abstract_controller/helpers.rb:22:在class_eval' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2 .13/lib/abstract_controller/helpers.rb:22:in中继承' from C:/RailsInstaller/Ruby1.9.3/ lib/ruby​​/gems/1.9.1/gems/actionpack-3.2 .13/lib/action_controller/metal/params_wrapper.rb:135:在inherited' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2 .13/lib/abstract_controller/railties/routes_helpers.rb:7:in块中(2级)在 与' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2 .13/lib/action_controller/railties/paths.rb:7:in block (2 levels) in with' from C:/Sites/rails_projects/sample_app/app/controllers/application_cont roller.rb:1:in' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport- 3.2.13/lib/active_support/dependencies.rb:251:在require' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport- 3.2.13/lib/active_support/dependencies.rb:251:in块中要求' from C:/ RailsInstaller /Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport- 3.2.13/lib/active_support/dependencies.rb:236:load_dependency' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport- 3.2.13/lib/active_support/dependencies.rb:251:in需要C:/RailsInstaller/Ruby1.9.3/lib中的' /ruby/gems/1.9.1/gems/activesupport- 3.2.13/lib/active_support/dependencies.rb:359:在require_or_load' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport- 3.2.13/lib/active_support/dependencies.rb:313:in depend_on' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/ 1.9.1/gems/activesupport- 3.2.13/lib/active_support/dependencies.rb:225:require_dependency' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1 3/lib/rails/engine.rb:439:in block(2 levels)in eager_load!' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems /1.9.1/gems/railties-3.2.1 3/lib/rails/engine.rb:438:在each' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1 3/lib/rails/engine.rb:438:in块中eager_load!' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9 .1/gems/railties-3.2.1 3/lib/rails/engine.rb:436:在each' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1 3/lib/rails/engine.rb:436:in eager_load!' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems /railties-3.2.1 3/LIB /轨道/应用/ finisher.rb:53:在block in <module:Finisher>' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1 3/lib/rails/initializable.rb:30:in instance_exec” 从C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties- 3.2.1 3/lib/rails /可初始化。rb:30:run' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1 3/lib/rails/initializable.rb:55:in块中run_initializers' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1 3/lib/rails/initializable.rb:54 :each' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1 3/lib/rails/initializable.rb:54:in run_initializers' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1 3/lib/rails/application.rb:136:in initialize!' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1 3/lib/rails/railtie/configurable.rb:30:in method_missing' 从C:/Sites/rails_projects/sample_app/config/environment.rb:5:<top (required)>' from C:/Sites/rails_projects/sample_app/spec/spec_helper.rb:3:in requir E ' 从C:/Sites/rails_projects/sample_app/spec/spec_helper.rb:3:<top ( required)>' from C:/Sites/rails_projects/sample_app/spec/requests/static_pages_spec. rb:1:in需要' 从C:/网站/ rails_projects/sample_app /规格/请求/ static_pages_spec。 rb:1:<top (required)>' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1 1.1/lib/rspec/core/configuration.rb:780:in从C加载' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1 1.1/lib/rspec/core/configuration.rb: 780:在block in load_spec_files' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1 1.1/lib/rspec/core/configuration.rb:780:in map' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1 1.1/lib/rspec/core/configuration.rb:780:in load_spec_files' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1 1.1/lib/rspec/core/command_line.rb:22:in从C运行' C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1 1.1/lib/rspec/core/runner.rb:69:在run' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1 1.1/lib/rspec/core/runner.rb:8:in block in自动运行”

我的编码的页面:

个佣工\ application.helper.rb

def full_title(page_title) 
base_title = "Ruby on Rails Tutorials Sample App" 
if page_title.empty? 
    base_title 
else 
    "#{base_title} | #{page_title}" 
end 
    end 
    end 

Static_pages_helper.rb

module StaticPagesHelper 
end 

Application.html.erb

<title><%= full_title(yield(:title)) %></title> 
<%= stylesheet_link_tag "application", media: "all" %> 
<%= javascript_include_tag "application" %> 
<%= csrf_meta_tags %> 
<%= render 'layouts/shim' %>  
</head> 
<body> 
    <%= render 'layouts/header' %> 
    <div class="container"> 
    <%= yield %> 
    <%= render 'layouts/footer' %> 
    </div> 
    </body> 
    </html> 

规格\请求\ static_pages_spec.rb

require 'spec_helper' 

describe "Static pages" do 

subject { page } 

describe "Home page" do 
before { visit root_path } 

it { should have_selector('h1', text: 'Sample App') } 
it { should have_selector('title', text: full_title('')) } 
it { should_not have_selector 'title', text: '| Home' } 
end 

describe "Help page" do 
before { visit Help_path } 

it { should have_selector('h1', text: 'Help') } 
it { should have_selector('title', text: full_title('Help')) } 
end 

describe "About page" do 
before { visit About_path } 

it { should have_selector('h1', text: 'About') } 
it { should have_selector('title', text: full_title('About Us')) } 
end 

describe "Contact page" do 
before { visit Contact_path } 

it { should have_selector('h1', text: 'Contact') } 
it { should have_selector('title', text: full_title('Contact')) } 
end 
end 

的routes.rb

SampleApp::Application.routes.draw do 

match '/static_pages/home' => 'static_pages#home' 
match '/Help', to: 'static_pages#Help' 
match '/About', to: 'static_pages#About' 
match '/Contact', to: 'static_pages#Contact' 

root to: 'static_pages#home' 

about.html.erb

<% provide(:title, "About Us") %> 
<h1>About Us</h1> 
    <p> 
The <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a> 
is a project to make a book and screencasts to teach web development 
with <a href="http://rubyonrails.org/">Ruby on Rails</a>. This 
is the sample application for the tutorial. 
    </p> 
    </body> 
    </html> 

contact.html.erb

% provide(:title, 'Contact') %> 
    <h1>Contact</h1> 
    <p> 
    Contact Ruby on Rails Tutorial about the sample app at the 
    <a href="http://railstutorial.org/contact">contact page</a>. 
    </p> 

help.html.erb

<% provide(:title, 'Help') %> 
    <!DOCTYPE html> 
    <html> 
<head> 
    <title>Ruby on Rails Tutorial Sample App | <%= yield(:title) %></title> 
</head> 
<body> 
    <h1>Help</h1> 
    <p> 
Get help on the Ruby on Rails Tutorial at the 
<a href="http://railstutorial.org/help">Rails Tutorial help page</a> 
To get help on this sample app, see the 
<a href="http://railstutorial.org/book">Rails Tutorial book</a>. 
    </p> 
    </body> 
    </html> 

home.html.erb

<div class="center hero-unit"> 
    <h1>Welcome to the Sample App</h1> 

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

    <%= link_to "Sign up now!", '#', class: "btn btn-large btn-primary" %> 
    </div> 

    <%= link_to image_tag("rails.png", alt: "Rails"), 'http://rubyonrails.org/' %> 

utilities.rb

def full_title(page_title) 
base_title = "Ruby on Rails Tutorial Sample App" 
if page_title.empty? 
base_title 
else 
"#{base_title} | #{page_title}" 
end 
end 

应用。RB

  require File.expand_path('../boot', __FILE__) 

     # Pick the frameworks you want: 
    require "active_record/railtie" 
    require "action_controller/railtie" 
    require "action_mailer/railtie" 
    require "active_resource/railtie" 
    require "sprockets/railtie" 
    # require "rails/test_unit/railtie" 

    if defined?(Bundler) 
    # If you precompile assets before deploying to production, use this line 
    Bundler.require(*Rails.groups(:assets => %w(development test))) 
     # If you want your assets lazily compiled in production, use this line 
     # Bundler.require(:default, :assets, Rails.env) 
     end 

    module SampleApp 
    class Application < Rails::Application 
    # Settings in config/environments/* take precedence over those specified here. 
    # Application configuration should go into files in config/initializers 
    # -- all .rb files in that directory are automatically loaded. 

    # Custom directories with classes and modules you want to be autoloadable. 
    # config.autoload_paths += %W(#{config.root}/extras) 

    # Only load the plugins named here, in the order given (default is alphabetical). 
    # :all can be used as a placeholder for all plugins not explicitly named. 
    # config.plugins = [ :exception_notification, :ssl_requirement, :all ] 

    # Activate observers that should always be running. 
    # config.active_record.observers = :cacher, :garbage_collector, :forum_observer 

# Set Time.zone default to the specified zone and make Active Record auto-convert to 
this zone. 
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 
    # config.time_zone = 'Central Time (US & Canada)' 

# The default locale is :en and all translations from config/locales/*.rb,yml are auto 
loaded. 
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 
    # config.i18n.default_locale = :de 

# Configure the default encoding used in templates for Ruby 1.9. 
config.encoding = "utf-8" 

# Configure sensitive parameters which will be filtered from the log file. 
config.filter_parameters += [:password] 

# Enable escaping HTML in JSON. 
config.active_support.escape_html_entities_in_json = true 

# Use SQL instead of Active Record's schema dumper when creating the database. 
# This is necessary if your schema can't be completely dumped by the schema dumper, 
# like if you have constraints or database-specific column types 
# config.active_record.schema_format = :sql 

# Enforce whitelist mode for mass assignment. 
# This will create an empty whitelist of attributes available for mass-assignment for 
all models 
# in your app. As such, your models will need to explicitly whitelist or blacklist 
accessible 
# parameters by using an attr_accessible or attr_protected declaration. 
config.active_record.whitelist_attributes = true 

# Enable the asset pipeline 
config.assets.enabled = true 

# Version of your assets, change this if you want to expire all your assets 
config.assets.version = '1.0' 
    end 
end 

github上地址: https://github.com/froeal01/sample_app

试图启动服务器,这个错误产生:

退出 C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/ 1.9.1/gems/activesupport-3.2.13/lib/ac tive_support/dependencies.rb:245:在load中:C:/ Sites/rails_projects/sample_app/c onfig/routes.rb:64:语法错误,意外的keyword_end,期待$ end(语法 错误)

+0

您是否使用'bundle install'来安装rspec-rails?事后重新启动服务器吗?你做了'rake db:test:prepare'。这些是显而易见的事情要尝试。 – 2013-03-25 17:34:21

+0

你好。刚刚尝试了你的建议,没有任何东西当我打开本地主机(no/home,/ about ...等)时出现此错误:StaticPagesController#home中的SyntaxError C:/Sites/rails_projects/sample_app/app/helpers/application_helper.rb:12:语法错误,意外的关键字结束,期待$结束 – user2201289 2013-03-25 18:36:07

+0

其他页面仍然有“路由错误”没有路由匹配。 – user2201289 2013-03-25 18:37:29

回答

0

您的申请助手缺少end

def full_title(page_title) 
    base_title = "Ruby on Rails Tutorials Sample App" 
    if page_title.empty? 
    base_title 
    else 
    "#{base_title} | #{page_title}" 
    end 
end 

您如何定义路线存在问题。 Rails路由都是小写的。

SampleApp::Application.routes.draw do 
    get "home",  :to => "static_pages#home" 
    get "help",  :to => "static_pages#help" 
    get "about", :to => "static_pages#about" 
    get "contacts", :to => "static_pages#contacts" 
end 

因此,你的路线有关网页应about_path代替。

+0

嗨本杰明,感谢评论。我实际上有两个结束,但由于某种原因,它没有在代码中复制。所以我想这可能不是原因 – user2201289 2013-03-25 18:56:36

+0

请看我更新的回复。这也有助于正确设置你的答案。 – 2013-03-26 05:38:21

+0

嗨本杰明,谢谢你的跟进回复。不幸的是它仍然不起作用。这是我现在得到的第一个错误:'C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/ac tive_support/dependencies.rb:251:in 'require':C:/Sites/rails_projects/sample_app/app/helpers/application_helper.rb:9:语法错误,意外的keyword_end,期待$ end(SyntaxError)'以及我的原始文章中的长列表。当我打开服务器时,我现在也收到了这个。 StaticPagesController中的语法错误#关于。 – user2201289 2013-03-26 13:41:28

相关问题