Я в какой-то странной ситуации, когда получаю странную ошибку с вложенными ресурсами.RoutingError с вложенными ресурсами и уничтожением
У меня есть вложенный ресурс определяется следующим образом:
resources :users do
resources :comments, :only => [:create, :destroy]
end
Мой конечный пункт для комментариев является JSON только поэтому его контроллер определяется следующим образом. Обратите внимание, что я использую cancan и actAsApi gems.
class CommentsController < ApplicationController
load_and_authorize_resource
self.responder = ActsAsApi::Responder
respond_to :json
# POST /comments.json
def create
flash[:notice] = 'Comment was successfully created.' if @comment.save
respond_with(@comment, :api_template => :default)
end
# DELETE /comments/1.json
def destroy
@comment.destroy
respond_with(@comment, :api_template => :default)
end
Затем я могу отправить пост запрос на «/users/1/comments.json» с некоторыми параметрами запроса и комментарии будут получать созданы, как ожидалось. К сожалению, я получаю сообщение об ошибке, когда он пытается найти разрушающее действие:
Completed 404 Not Found in 169ms
ActionController::RoutingError (No route matches {:action=>"destroy", :controller=>"comments", :id=>#<Comment id: 34, user_id: 1, text: "test test test", created_at: "2012-02-28 06:45:49", updated_at: "2012-02-28 06:45:49">}):
app/controllers/comments_controller.rb:12:in `create'
В качестве дополнительной информации, если изменить routes.rb к этому:
resources :comments, :only => [:destroy]
resources :users do
resources :comments, :only => [:create]
end
Я не вижу никакой ошибки.