Ruby Hartl教程:3.2尝试清理代码时出错
当我运行测试时,我收到这条消息(我猜它通过了),但当我转到本地host300时,我在所有页面上都会收到以下消息:无路由匹配[GET]“/about” 我在这方面已经坚持了大约4个小时:( 这是我收到的测试报告- C:\Sites\rails\u projects\sample\u app>bundle exec rspec spec/requests/static\u页面_ 规范rb C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/ac tive\u support/dependencies.rb:251:inRuby Hartl教程:3.2尝试清理代码时出错,ruby,Ruby,当我运行测试时,我收到这条消息(我猜它通过了),但当我转到本地host300时,我在所有页面上都会收到以下消息:无路由匹配[GET]“/about” 我在这方面已经坚持了大约4个小时:( 这是我收到的测试报告- C:\Sites\rails\u projects\sample\u app>bundle exec rspec spec/requests/static\u页面_ 规范rb C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/act
require':C:/Sites/rails\u projects/sample\u ap
p/app/helpers/application\u helper.rb:12:语法错误,意外的关键字\u end,例如
推测$end(SyntaxError)
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-
3.2.13/lib/active_support/dependencies.rb:251:in
block in require'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-
3.2.13/lib/active_-support/dependency.rb:236:inload_-dependency'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-
3.2.13/lib/active_支持/依赖项。rb:251:in
require'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-
3.2.13/lib/active_support/dependencies.rb:359:inrequire_或_load'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-
3.2.13/lib/active\u support/dependencies.rb:313:in
dependence\u'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-
3.2.13/lib/active_-support/dependency.rb:225:inrequire_-dependency'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2
.13/lib/abstract\u controller/helpers.rb:135:in
模块中的块,用于\u helpers'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2
.13/lib/abstract_controller/helpers.rb:131:inmap!'
来自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
.13/lib/action\u controller/metal/helpers.rb:92:inmodules\u for\u helpers'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2
.13/lib/abstract_controller/helpers.rb:95:in
helper'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2
.13/lib/abstract_controller/helpers.rb:159:indefault_helper_module!'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2
.13/lib/abstract_controller/helpers.rb:22:in
block in inherited'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2
.13/lib/abstract\u controller/helpers.rb:22:inclass\u eval'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2
.13/lib/abstract_controller/helpers.rb:22:in
inherited'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2
.13/lib/action_controller/metal/params_wrapper.rb:135:ininherited'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2
.13/lib/abstract\u controller/railties/routes\u helpers.rb:7:in
block(2层)in
带着
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2
.13/lib/action_controller/railties/paths.rb:7:in块(2层)中带'
来自C:/Sites/rails\u projects/sample\u app/app/controllers/application\u cont
roller.rb:1:in
'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-
3.2.13/lib/active_支持/依赖项。rb:251:inrequire'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-
3.2.13/lib/active_support/dependencies.rb:251:in
block in require'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-
3.2.13/lib/active_-support/dependency.rb:236:inload_-dependency'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-
3.2.13/lib/active_支持/依赖项。rb:251:in
require'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-
3.2.13/lib/active_support/dependencies.rb:359:inrequire_或_load'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-
3.2.13/lib/active\u support/dependencies.rb:313:in
dependence\u'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-
3.2.13/lib/active_-support/dependency.rb:225:inrequire_-dependency'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1
3/lib/rails/engine.rb:439:in
块(2层)处于加载状态
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1
3/lib/rails/engine.rb:438:ineach'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1
3/lib/rails/engine.rb:438:in
block-in-eager\u-load!'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1
3/lib/rails/engine.rb:436:ineach'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1
3/lib/rails/engine.rb:436:in
eager\u load!'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1
3/lib/rails/application/finisher.rb:53:inblock in'
来自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/initializable.rb:30:inrun'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1
3/lib/rails/initializable.rb:55:in
run_initializer'中的块
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1
3/lib/rails/initializable.rb:54:ineach'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/g
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
module StaticPagesHelper
end
<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>
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
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'
<% 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>
% 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>
<% 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>
<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/' %>
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
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
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
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