我正在关注Rails 教程,我在测试中遇到了一些问题,但一个特别的错误是:
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)>'
我不明白为什么如果我的路线上有这个会发生这种情况.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"}