我有一個奇怪的問題:我收到以下錯誤登錄,並試圖回家以下網址localhost:3000/
沒有路由匹配{:動作=>「時間表」,:控制器=>「用戶」}
後「沒有路由匹配{:行動=>」 日程表 「:控制器=> 」用戶「}」
這裏是routes.rb中:
Ikky::Application.routes.draw do
root to: 'static_pages#home'
resources :users do
member do
get 'schedule'
end
end
rake routes
返回下列:
root / static_pages#home
schedule_user GET /users/:id/schedule(.:format) users#schedule
users GET /users(.:format) users#index
POST /users(.:format) users#create
[...]
引入我的schedule_user路由時出現此問題。
這裏是我的users_controller:
class UsersController < ApplicationController
before_filter :signed_in_user, only: [:index, :edit, :update, :destroy, :schedule]
before_filter :correct_user, only: [:edit, :update]
before_filter :admin_user, only: :destroy
def schedule
@user = User.find(params[:id])
@spots = @user.spots.paginate(page: params[:page])
@spot = current_user.spots.build if signed_in?
end
這裏是static_pages_controller:
class StaticPagesController < ApplicationController
def home
@spot = current_user.spots.build if signed_in?
end
下面是部分共享/ USER_INFO:
<a href="<%= user_path(current_user) %>">
<%= gravatar_for current_user, size: 52 %>
</a>
<h1>
<%= current_user.name %>
</h1>
<span>
<%= link_to "view my profile", current_user %>
</span>
<span>
<%= pluralize(current_user.spots.count, "spots") %>
</span>
謝謝您的幫助!
P.S:我是一個初學者很抱歉,如果我的代碼是一個爛攤子......
解決這個問題是否有/ static_pages /主視圖的任何環節爲用戶/時間表? –
沒有鏈接到用戶/時間表,只有部分用戶信息:'<%if signed_in? %> <%= render'shared/user_info'%><% else %> ' – lgerard
正常情況下,如果我們將成員路徑放在沒有ID的情況下就會發生。例如:link_to「A」,「users/schedule」或schedule_user_path。 –