ネストしたリソースで奇妙なエラーが発生するような気がします。コメントのネストされたリソースと破棄するRoutingError
resources :users do
resources :comments, :only => [:create, :destroy]
end
私のエンドポイントは、次のようにだけので、そのコントローラーが定義されているJSONです:
私は、ネストされたリソースは以下のように定義されています。私はcancanとactsAsApiの宝石を使用しています。期待されるように、私はその後、いくつかのリクエストパラメータとコメントで「/users/1/comments.json」にPOSTリクエストを送信することができます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
が作成されます。私はこれにroutes.rbをを変更した場合、追加の情報として
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'
:残念ながら、私はそれを破壊するアクションを検索しようと、エラーを取得しています
resources :comments, :only => [:destroy]
resources :users do
resources :comments, :only => [:create]
end
私はすべてのエラーが表示されません。