2

我是 Ruby on Rails 的新手,不断收到以下错误消息:

ActionController::RoutingError in Users#index 

"No route matches {:action=>"following", :controller=>"users"}"

Showing /app/views/layouts/_navbar.html.erb......where line #19 raised:

Extracted source (around line #19):
16: </td>
17:                 </div>
18:        
19:                 <div id="secondlink"><td class="rite"><li><% if signed_in? %><%= link_to "Profile", current_user %></li><li><%= link_to "watching", following_user_path(@user)%></li><li><%= link_to "Users", users_path %></li><li><%= link_to "Sign out", signout_path, :method => :delete %>
20:       <% else %>
21: <%= link_to "Sign in", signin_path %></li><% end %>
22:      

当我单击链接(在我的导航栏中)以显示分页用户的完整列表时,会发生此路由错误”

我的 routes.rb 文件中包含以下内容:

 Mvp::Application.routes.draw do
   resources :users do
    member do
      get :following, :followers
    end
   end

UsersController 中的“以下”操作:

def following
    @title = "Following"
    @user = User.find(params[:id])
    @users = @user.following.paginate(:page => params[:page])
    render 'show_follow'
end
4

2 回答 2

2

我不能肯定地说,但我的第一个猜测是在下面

<%= link_to "watching", following_user_path(@user)%>

变量@user为零。我不知道为什么它是 nil,但如果它是 nil,这就是你会得到的错误。

于 2012-04-10T00:35:37.017 回答
0

rake routes输出_

following_user GET    /users/:id/following(.:format) users#following
followers_user GET    /users/:id/followers(.:format) users#followers
         users GET    /users(.:format)               users#index
               POST   /users(.:format)               users#create
      new_user GET    /users/new(.:format)           users#new
     edit_user GET    /users/:id/edit(.:format)      users#edit
          user GET    /users/:id(.:format)           users#show
               PUT    /users/:id(.:format)           users#update
               DELETE /users/:id(.:format)           users#destroy

所以你得到了你的路由 - 定义了控制器映射。

接下来要检查的事项:

  • 你有你定义的following动作吗UsersController

  • GET您是否使用方法请求服务器响应

于 2012-04-10T00:01:10.707 回答