Michael Hartl Rails 자습서 제 3 장 로컬 서버의 라우팅 오류
-
21-12-2019 - |
문제
이것은 루비 광산을 사용하는 동안 일단 일어난 일이 일어나고, 윗격 텍스트 2를 사용하여 순수한 텍스트 경로를 사용하는 동안 일단 일어났습니다.
모든 것은 처음에 훌륭하게 작동합니다. 로컬 호스트가 빨리로드됩니다. 세 개의 생성 된 정적 페이지가 잘로드 된 다음, 붐, 단지 깨졌습니다. 마스터 브랜치를 정적 페이지 지점으로 병합 한 직후에 이것이 일어나는 일이 거의 100 % 긍정적입니다. 정적 페이지는 단지로드되지 않습니다 (어느 부분 중 하나에 - 나는 일이 하나의 지점에서 여전히 작동하고 있는지 여부를 알아보십시오.
대신 다음과 같은 오류가 발생합니다.
경로 없음 [get] "/ home"
(동일한 오류 메시지가 다른 두 페이지에 적용)
여기 홈페이지의 전체 추적 :
Rails.root: C:/Sites/sample
actionpack (4.0.8) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (4.0.8) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.8) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.8) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.0.8) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.0.8) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.0.8) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.0.8) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.0.8) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.8) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.8) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.0.8) lib/rails/engine.rb:511:in `call'
railties (4.0.8) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
I:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
I:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
I:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
Routes
Routes match in priority from top to bottom
Helper HTTP Verb Path Controller#Action
Path / Url
static_pages_home_url GET /static_pages/home(.:format) static_pages#home
static_pages_help_url GET /static_pages/help(.:format) static_pages#help
static_pages_about_url GET /static_pages/about(.:format) static_pages#about
.
routes.rb 파일은 다음과 같습니다 (자습서와 일치하는) :
Sample::Application.routes.draw do
get "static_pages/home"
get "static_pages/help"
get "static_pages/about"
end
.
static_pages_controller.rb 파일은 다음과 같습니다 (이는 튜토리얼과 일치합니다).
class StaticPagesController < ApplicationController
def home
end
def help
end
def about
end
end
.
나는 이것에 대한 완전한 손실에있다.
와이 기능을 찾았습니다. .rb 파일은 자습서에서와 동일한 구문을 사용합니다.
Off-Chachare가 필요합니다. 여기에서는 static_pages_spec.rb 파일 rspec 테스트를 위해 사용 중입니다.
require 'spec_helper'
describe "StaticPages" do
describe "Home page" do
it "should have the content 'Sample App'" do
visit '/static_pages/home'
expect(page).to have_content('Sample App')
end
it "should have the title 'Home'" do
visit '/static_pages/home'
expect(page).to have_title("Ruby on Rails Tutorial Sample App | Home")
end
end
describe "Help page" do
it "should have the content 'Help'" do
visit '/static_pages/help'
expect(page).to have_content('Help')
end
it "should have the title 'Help'" do
visit '/static_pages/help'
expect(page).to have_title("Ruby on Rails Tutorial Sample App | Help")
end
end
describe "About page" do
it "should have the content 'About Us'" do
visit '/static_pages/about'
expect(page).to have_content('About Us')
end
it "should have the title 'About Us'" do
visit '/static_pages/about'
expect(page).to have_title("Ruby on Rails Tutorial Sample App | About Us")
end
end
end
. 해결책
/home
의 경로가 없습니다. 따라서 No route matches [GET] "/home"
가있는 경로가있는 이유를 가져오고 URL 브라우저에 입력하면 홈페이지 (즉, /static_pages/home
)
localhost:3000/static_pages/home
를 /home
get '/home', to: 'static_pages#home'
.