0

我有一个奇怪的问题:登录并尝试通过 URL 回家后出现以下错误localhost:3000/

" 没有路线匹配 {:action=>"schedule", :controller=>"users"} "

这是 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

这是部分 shared/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>

谢谢您的帮助!

PS:如果我的代码一团糟,我是初学者,很抱歉...

4

1 回答 1

0

通常情况下,如果我们将member路径放在不带id. 例如:link_to "A", 'users/schedule' or schedule_user_path

'users/#{user.id}/schedule'通过更正指向或的链接来解决此问题schedule_user_path(user.id)

于 2013-05-22T09:47:06.100 回答