所以,我有以下代碼。我想訪問timespans_path
, 但我不能。Rails無法找到路徑
<% 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
爲什麼會出現錯誤?我該如何解決它?
你也應該放在你'route.rb' –
份額的問題你的路由文件以及 – Abk
你必須增加資源:時間跨度在你的路由文件,否則路線助手不會明白timespans_path – Abk