ActionController的:: RoutingError:

时间:2012-09-18 16:39:50

标签: ruby-on-rails rspec routing

我跟随rails tutorial并且我在测试中遇到了一些问题,但是有一个特别的错误:

1) UsersController following pages when not signed in should protect 'following'
 Failure/Error: get :following, :id => 1
 ActionController::RoutingError:
   No route matches {:id=>1, :controller=>"users", :action=>"following"}
 # ./spec/controllers/users_controller_spec.rb:10:in `block (4 levels) in <top (required)>'

我不明白为什么如果我在我的routes.rb

上有这个
resources :users do
   member do
     get :following, :followers
   end
end

我的控制器是这样的:

class UsersController < ApplicationController
  before_filter :authenticate, :except => [:show, :new, :create]


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

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

这是我的rspec:

  it "should protect 'following'" do
    get :following, :id => 1
    response.should redirecto_to (new_selector_session_en_path) 
  end

也是我的路线:

following_user_en GET      /users/:id/following(.:format)                         {:action=>"following", :controller=>"users"}
following_user_es GET      /es/usuarios/:id/following(.:format)                   {:action=>"following", :controller=>"users"}
followers_user_en GET      /users/:id/followers(.:format)                         {:action=>"followers", :controller=>"users"}
followers_user_es GET      /es/usuarios/:id/followers(.:format)                   {:action=>"followers", :controller=>"users"}

0 个答案:

没有答案