2014-10-19 3 views
0

작동하지 : root "pages#index"루트 경로가 routes.rb 파일에서

pages_controller.rb 파일

class PagesController < ApplicationController 
    def index 
     render 'home' 
    end 

    def about 
    end 
    end 

보기 이름 home.html.haml

rake routes 반환

Prefix Verb URI Pattern  Controller#Action 
    home GET /home(.:format) pages#home 
    about GET /about(.:format) pages#about 

은 우리가 "라는 로컬 호스트 미안해,하지만 뭔가가 나왔어. 룽. "콘솔 말한다 레일에 ActionController::RoutingError (No route matches [GET] "/home"):

4.2.0.beta2

* 레일 버전

+0

무엇이 오류입니까? – Nithin

+0

어떤 버전의 레일? – JTG

+0

@nithin localhost는 "죄송합니다.하지만 문제가 발생했습니다."라고 말하면 콘솔에는 ActionController :: RoutingError (경로가 [GET] "/ home"과 일치하지 않습니다.)라고 표시되어 있습니다 : – Jadam

답변

1

실제로 콘솔 오류에 대한 편집, rake routesGET /home가에있는 홈 조치를 pages#home 일치하는 것을 말한다 페이지 컨트롤러.

routes.rb 파일을 더 표시 할 수 있습니까?

또한, 당신은 왜 당신이 렌더링보기를 지정하지 않으면 따라서 귀하의 색인 작업을

def index 
end 

될 수 있으며, 파일을 index.html.haml 당신의 home.html.haml 파일의 이름을 변경하지 않습니다 , Rails는 당신의 행동 이름을 가진보기를 찾으려고 노력할 것이다.

0

나는 당신의 routes.rb 파일을 업데이트 할 것입니다 : 벤자민에 의해 제안

root 'pages#index' 

get '/home', to: 'pages#index' 
get '/about', to: 'pages#about' 

을, 나는 그것이 더 나은 디자인 index.html.erb하기 위해 home.html.erb 이름을 바꿀 것이라고 생각하십니까 . 이렇게하면 색인 방법에서 render 'home'을 제거 할 수 있습니다.

이상한 점은 사용자의 rake routes 출력에/home이 없을 수있는 컨트롤러 방법 인 # home 페이지로 리디렉션된다는 것입니다.

관련 문제