2009-11-16 4 views
1

ruby ​​on rails의 뷰와 관련하여 문제가 있습니다. 기본적으로Ruby on Rails 뷰와 관련된 문제 (rhml/html.erb)

난 내가

를로드하려고하지만, 나는이 자리에 등을 발판 모두가 지금 index.html.erb

내에서 발견 코드를로드

http://localhost:3000/stores/에 잘 세부 사항을 나열하는 일반 프로젝트가

http://localhost:3000/stores/searchsearch.rhtml에서 코드를로드해야하며 (이 코드는 .html.erb로 변경해야합니까, 아니면 차이가 있습니까?) 단순히 파일 show.html.erb으로 이동하여 대신 해당 코드를 표시해야합니다 (이로 인해 pr 오페라가 전달되지 않는 등).

제가 잘못하고있는 것이 궁금 해서요. routes.rb 파일에서 뭔가를 설정해야합니까? (이 문제와 아무 상관이 있는지?)를 지원 고급의

ActionController::Routing::Routes.draw do |map| 
    map.resources :stores 
    map.resources :stores 

    map.connect ':controller/:action/:id' 
    map.connect ':controller/:action/:id.:format' 
end 

감사 많은이 각 질문에 대답하려고 노력하는 레일 프로젝트

답변

2

당신이 당신의 경로는 다음과 같이 파일을 설정할 것입니다 검색 작업을 추가하려면 :

ActionController::Routing::Routes.draw do |map| 
    map.resources :stores, :collection => { :search => :get } 

    map.connect ':controller/:action/:id' 
    map.connect ':controller/:action/:id.:format' 
end 

내가 search.rhtml도 작동하지만 파일 search.html.erb 이름을 지정 스틱 것입니다. 이것은 레일에 good guide for routing이고 특별히이 대답에 적용되는 here's the section입니다.

+0

감사합니다. – Erika

0

에 처음 루비로 :

  1. 중복 된 map.resources :stores이 있습니다. 하나이면 충분합니다.

  2. 네, 맞습니다. http://localhost:3000/stores/search은 search.html.erb를로드합니다. (컨트롤러에서 코드를 볼 수는 없지만 레일을 학습하는 과정에서 나는 respond_to로 컨트롤러 동작을 조정하지 않았다고 가정)

  3. show.html.erb보기로 이동해서는 안됩니다. StoresController를 보여줄 수 있습니까?