2017-03-15 4 views
0

RoR 안내서를 따르고 있으며 자습서에서 준비한 라우팅 파일이 내 컴퓨터에서 생성 된 것과 다릅니다.라우팅 오류가 발생하는 이유는 무엇입니까?

Routing Error No route matches [GET] "/say/hello"

그 이유는 무엇입니까 : 튜토리얼에 하나 내가 라우팅 오류가 발생하고 있기 때문에

Lecture::Application.routes.draw.do 
    get 'say/hello' 

내 파일이 달라 지나요

Rails.application.routes.draw.do 
    get 'say/hello' 

을 gererated했다?

+0

을해야 레이크 경로의 출력이 무엇인지 –

+0

레이크 라우트를 입력하고 이것을 얻었습니다 : 접두사 Verb URI 패턴 컨트롤러 # 액션 say_hello GET /say/hello(.:format) say # hello – Owen

+0

안녕하세요, 오버플로를 환영합니다. 'rake route' 결과물을 원래의 질문에 넣으시겠습니까? 주석의 형식은 정말 읽기가 어렵습니다 ... : P :) 참고 : 차이점은 아마도 레일 버전 차이 일 것입니다. 튜토리얼에서 사용하는 버전은 무엇입니까? 어떤 버전을 사용합니까? –

답변

0

경로의 위치를 ​​지정해야합니다. 예를 들어 :

def hello 
    #This is my hello action 
end 
:

형식에
get 'say/hello', to: 'say#hello' 

(가)

액션 사용을 정의하려면 'controller_name 번호의 controller_action이'입니다 :

get '/patients/:id', to: 'patients#show' 

또는 귀하의 경우 (Rails Routing from the Outside In)

+0

"get hello '를 시도해 보았습니다.'hello '라고 말하고 같은 오류가 발생했습니다. – Owen

+0

컨트롤러의 이름은 무엇입니까? 그리고 "hello"액션이 정의되어 있습니까? – AytanLeibowitz

+0

컨트롤러는 "say"이고 "hello"액션은 컨트롤러에 정의되어 있습니다. 그게 내가 오류 메시지를 이해하지 못하는 이유입니다. 그 길의 어떤 길도 없다고 말하는 것은 내가 볼 수있는 한 거기의 길이다. – Owen

0

컨트롤러가 say 인 경우 그 컨트롤러 hello 방법

변화에

get 'say/hello', to: 'say#hello' 

,

get '/say/hello', to: 'say#hello' 

가 관찰 '/say/hello'. 당신이 컨트롤러를 가지고 있겠지 경우

,

유형 rails console에서 rake routes과 질문을 업데이트합니다.

0
#config/routes.rb 

get 'say/hello' => 'say#hello' #Here say is controller and hello is action 

#controllers/say_controller.rb 

class SayController < ApplicationController 
    def hello 
    ... 
    end 
end 
0

컨트롤러 파일은 다음과 같아야합니다

say_controller.rb 

Class SayController < ApplicationController 
    def hello 
    puts 'hello there' 
    end 
end 

당신의 routes.rb 파일이 포함되어 있어야합니다

routes.rb 

get '/anything/you_want/', to 'say#hello' 

이 트릭

관련 문제