Michael Hartl 's Rails 튜토리얼을 수행 중이지만 Listing 5.28 (녹색 대신 RED 테스트를 얻음)에서 새로운 경로와 일치하도록 테스트를 변경했다. 모든 페이지Rails 튜토리얼 정적 페이지 경로 테스트 빨간색 (5.28)
오류 (/,/약/접촉/도움말) :
ActionController::UrlGenerationError: No route matches {:action=>"/*", :controller=>"static_pages"}
routes.rb
Rails.application.routes.draw do
root 'static_pages#home'
get '/help', to: 'static_pages#help'
get '/about', to: 'static_pages#about'
get '/contact', to: 'static_pages#contact'
end
테스트/컨트롤러/static_pages_controller_test.rb
require 'test_helper'
class StaticPagesControllerTest < ActionController::TestCase
test "should get home" do
get root_path
assert_response :success
assert_select "title", "Ruby on Rails Tutorial Sample App"
end
test "should get help" do
get help_path
assert_response :success
assert_select "title", "Help | Ruby on Rails Tutorial Sample App"
end
test "should get about" do
get about_path
assert_response :success
assert_select "title", "About | Ruby on Rails Tutorial Sample App"
end
test "should get contact" do
get contact_path
assert_response :success
assert_select "title", "Contact | Ruby on Rails Tutorial Sample App"
end
end
static_pages_controller.rb
class StaticPagesController < ApplicationController
def home
end
def help
end
def about
end
def contact
end
end
당신이 다른 어떤 코드를 볼 필요가 있다면 알려주세요! 다음과 같이 추가하려고 시도했습니다. '*'는 각 경로를 얻은 후에 발생하지만 아무런 소용이 없습니다.
Ruby/rails 버전 문제인지는 모르겠지만 IDE에서 Rails 4.2.2 및 Ruby 2.3.0을 사용하고 있지만 "Rails test"(Hartl이 사용하도록 지시 한대로)가 작동하지 않습니다 "테스트 명령을 찾을 수 없습니다"). 그것이 더 큰 문제에 대한 암시인지 또는 관련이없는 것인지 확실하지 않습니다. 미리 감사드립니다!
EDIT : 아래의 경로를 사용하는 링크가 올바르게 렌더링되어 테스트에 실패했습니다.
<%= link_to "Home", root_path %>
<%= link_to "Help", help_path %>
버전이 문제가되었습니다. 이전 장에서 필자는 4.2.2를 사용하여 샘플 응용 프로그램을 작성하라고 지시 한 구형의 이전 판에있었습니다. 그런 다음 몇 가지 챕터가 나중에 5.0.0에 대한 최신 버전의 책으로 전환되었습니다. 알아 차리지 못한 채 얼마 지나지 않았는지 확신 할 수는 없지만 처음부터 앱을 시작했습니다 (Hartl의 책 5.0.0 버전에 있음을 확신합니다). 이제 모든 것이 매력처럼 작동합니다. 확실히 올바른 버전에 있는지 확인하는 소중한 교훈을 얻었습니다. 에디션! – user2521295