Ruby on rails rails路由-在嵌套命名空间中找不到操作-获取为
以下请求应调用标记控制器的show操作。但我明白了Ruby on rails rails路由-在嵌套命名空间中找不到操作-获取为,ruby-on-rails,routing,namespaces,Ruby On Rails,Routing,Namespaces,以下请求应调用标记控制器的show操作。但我明白了 http://localhost:3000/api/v0/tags/seeded The action 'seeded' could not be found for Api::V0::TagsController 在routes.rb中 namespace :api do namespace :v0 do get "/users/:username" => 'users#show', :as => 'u
http://localhost:3000/api/v0/tags/seeded
The action 'seeded' could not be found for Api::V0::TagsController
在routes.rb中
namespace :api do
namespace :v0 do
get "/users/:username" => 'users#show', :as => 'user'
get '/tags/:name' => 'tags#show', :as => 'tag'
end
end
在app/controllers/api/v0/tags_controller.rb中
class Api::V0::TagsController < ApplicationController
def show
render :json => Api::V0::Serializers::Tag.new(params[:name])
end
end
我使用Rails 3.0.11
更新
您使用的是哪个版本的rails?您的示例在Rails 3.1.1上非常有用。我在Rails 3.0.11上也很有用。您能显示rake路由的输出吗?在您的路由文件中还有什么没有显示给我们的?您使用的是哪个版本的rails?您的示例在Rails 3.1.1上非常有用。我在Rails 3.0.11上也很有用。你能显示rake路由的输出吗?在你的路由文件中还有什么你没有显示给我们的?
http://localhost:3000/api/v0/tags/seeded.json
$ rake routes|grep api
api_v0_user GET /api/v0/users/:username(.:format) {:controller=>"api/v0/users", :action=>"show"}
api_v0_tag GET /api/v0/tags/:name(.:format) {:controller=>"api/v0/tags", :action=>"show"}