2

DB를 사용하지 않고 인덱스 및 약 페이지로 간단한 응용 프로그램을 코딩하고 싶습니다. 모든 텍스트가 뷰에 있습니다. 하지만 내 컨트롤러 메서드를 호출하여 뷰를 변경할 수는 없습니다. 여기 은 (home_controller.rb) 컨트롤러간단한 Ruby on Rails 앱

class HomeController < ApplicationController 

    def index 
    end 

    def about 
    end 

end 

레이아웃 :

!!! 
%html 
    %head 
    %title Title 
    = stylesheet_link_tag "application" 
    = javascript_include_tag "application" 
    = csrf_meta_tags 
    %body 
    .wrapper 
     = yield 
     .footer 

홈 인덱스보기 :보기에 대한

%h2 Index 
%h1 
    This is example page 
%p 
    = link_to "Home", root_path 
    = link_to "About", :controller => "home", :action => "index" 
%p 
    "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." 

:

routes.rb에서
%h2 About 
%h1 
    This is about page 
%p 
    = link_to "Home", root_path 
    = link_to "About", :controller => "home", :action => "about" 
%p 
    Lorem ipsum 

나는있다. 내가 내 도메인을 호출 할 때 내가 쓸 때

, 내가 인덱스를 얻을 수 있습니다 : 도메인/가정/색인은 내가 얻을

어떤 경로 일치하는 항목이 없습니다 "/ 홈/색인"

[GET]

전화 할 때도 마찬가지입니다. 어떻게 내 페이지에 전화 할 수 있습니까? 레이크 노선 줘 :

루트/{: 컨트롤러 => "홈", : 행동 => "인덱스"}

답변

2

당신은뿐만 아니라 그 경로를 정의해야합니다. 자동으로 나타나지 않습니다.

예를 들어, 다음은 기본 생성 된 routes.rb에서 찾을 수있는 내용입니다 (끝에 있음).

# This is a legacy wild controller route that's not recommended for RESTful applications. 
    # Note: This route will make all actions in every controller accessible via GET requests. 
    # match ':controller(/:action(/:id(.:format)))' 

의 주석이를 당신은 /home/index/home/about에 액세스 할 수 있어야합니다. 핸들러 => [: ERB : 추가 귀하의 경로에 다음과 같은

+0

템플릿 {에 대한 템플릿 홈/약, 응용 프로그램/누락 누락 된 선 위에 파일 빌더 : coffee, : haml], : formats => [: html], : : locale => [: en, : en]}을 입력하십시오. 검색된 위치 : * "/ mnt/_Projects/exapmle2/app/views"wtf? 나는 이것을 가지고있다 – byCoder

+0

당신은'/ app/views/home/about.html.haml'을 가지고 있습니까? –

+0

ofc 나는 가지고있다, 이것은 흥미 롭다 – byCoder

1

시도는 root :to => ...

get 'home/index' 
get 'home/about' 
+0

백 슬래시는 확실합니까? :) –

+0

@Sergio 최근에 창문에서 작업 해 주셔서 감사합니다. –