使用Rails 3.0.7,我创建了我们的应用程序的API,而且我有这样的设置:
的routes.rb
namespace :api do
namespace :v1 do
match "connect" => "users#login", :via => :post
match "disconnect" => "users#logout", :via => :post
resources :users
match "users/:id/foos" => "foos#list", :via => :get
match "users/:id" => "users#update", :via => :put
match "foos/:id/bars" => "bars#list_by_foo", :via => :get
match "foos/:id" => "foos#show", :via => :get, :constraints => { :id => /\d+/ }
match "bars/:id" => "bars#show", :via => :get
end
end
# other routes here e.g.
match "users/find" => "users#find_by_name", :via => :get
match "users" => "users#create", :via => :post
然后,我有我的正常app/controllers/application_controller.rb
和app/controllers/users_controller.rb
文件以及我的app/controllers/api/v1/application_controller.rb
和app/controllers/api/v1/users_controller.rb
文件被定义如下所示:
class Api::V1::ApplicationController < ApplicationController
before_filter :verify_access
def verify_access
# some code here
end
end
class Api::V1::UsersController < Api::V1::ApplicationController
skip_before_filter, :except => [:show, :update, :delete]
end
一切似乎之前直到我推翻由两个UsersController和API :: V1 :: UsersController共享的方法是正确的工作 - 现在好像一切都指向UsersController即使我通过API / V1访问/用户的路线。
我在我束手无策试图弄明白。 有什么建议? 谢谢。 PS - 随时与任何约定,我忽略了我不应该或其他东西我可能会搞砸了:)发表评论