2014-03-19 2 views
0

그래서, 다음과 같은 코드가 있습니다. timespans_path, 에 액세스하고 싶지만 할 수 없습니다.레일이 경로를 찾을 수 없습니다

<% content_for :div_header do%> 
    <h1> Welcome, <%= @l_user.name %> </h1> 
<% end %> 

<% content_for :div_sub_header do %> 
    <ul> 
    <li><%= link_to "show entries", entries_path %></li> 
    <li><%= link_to "show groups", groups_path %> 
    <% if can? :read, Subgroup %> 
     , 
     <%= link_to " subgroups", subgroups_path %> 
     </li> 
    <% end %> 
    <li><%= link_to "show users", users_path %></li> 
    <li><%= link_to "show actioncodes", actioncodes_path %></li> 
    <li><%= link_to "show timespans", timespans_path %></li> 
    </ul> 
<% end %> 

난 항상 이러한 오류를 얻을 :

NameError in Application#welcome 
Showing C:/xampp/htdocs/fluxcapacitor/app/views/application/welcome.html.erb where line #16 raised: 
undefined local variable or method `timespans_path' for #<#<Class:0x58b8610>:0x58b7e18> 

이 내가 route.rb입니다 :

Fluxcapacitor::Application.routes.draw do 
    root 'application#welcome' 

    get 'login' => 'application#login' 
    post 'login' => 'application#process_login' 

    post '' => 'application#process_login' 

    post 'send_request_account_mail' => 'application#send_request_account_mail' 
    post 'send_forgot_password_mail' => 'application#send_forgot_password_mail' 

    get 'forgot_password' => 'application#forgot_password' 
    get 'request_account' => 'application#request_account' 

    get 'welcome' => 'application#welcome' 
    get 'logout' => 'application#logout' 

    if Rails.env.development? 
    get 'display_mail' => 'application#display_mail' 
    end 

    resources :users 

    get 'multiple_new' => 'users#multiple_new' 
    post 'multiple_new' => 'users#multiple_new' 
    post 'multiple_create' => 'users#multiple_create' 

    get 'users/:id/:hash/cal' => 'users#cal' 

    resources :actioncodes 

    resources :entries 

    resources :timespans 

    resources :groups do 
    member do 
     get 'search_admin' 
     post 'search_admin' 
     post 'add_admin' 
     get 'remove_admin' 
     post 'remove_admin' 
    end 
    end 

    resources :subgroups do 
    member do 
     get 'search_user' 
     post 'search_user' 
     post 'add_user' 
     get 'remove_user' 
     post 'remove_user' 

     get 'remove_admin' 
     post 'remove_admin' 
    end 
    end 
end 

가 왜 오류는 무엇입니까? 어떻게 해결할 수 있습니까?

+0

당신은 또한 당신의 경로뿐만 아니라 파일 –

+0

주을 route.rb'에 대한 질문에 넣어해야합니다 그렇지 않으면 경로 도우미가 timespans_path – Abk

+1

당신이 자원을 추가 할 필요가 당신의' – Abk

답변

1

당신의 route.rb에

resources :timespans 

추가

당신이 timespans라는 경로를 정의하지 않은, 그래서보기를 렌더링하는 데 어떤 URL 모르는 및 오류를 제기한다처럼 보이는
0

.

당신은 Timespan라는 모델은 다음 /timespans을 가리키는 timespans_path (다른 사람의 사이에서)라는 경로를 만들 것이다 루트 파일에 resources :timespans을 추가하는 경우. 모든를 나열 레이크 작업 rake routes을 사용할 수 있습니다,

get "/the_url", to: "the_controller#the_action", as: :timespans 

당신이 미래에 경로에 문제가있는 경우 :

또한 timespans 경로 :as 옵션을 사용하여 호출 임의의 경로, 예를 만들 수 있습니다 생성 된 라우트와 라우트 헬퍼의 이름은 디버깅에 매우 유용합니다.

관련 문제