ネストされた ActiveResource モデルがあります (つまり、別のモデルの名前空間内にあります)。save
レイズをコールしようとしています:
ActiveResource::MissingPrefixParam: client_id prefix_option is missing
必要なプレフィックスを指定するにはどうすればよいですか?
これが私のクラスです:
class Foo::Bar < ActiveResource::Base
self.site = "http://www.example.com"
self.prefix = "/clients/:client_id"
self.element_name = "policy"
self.collection_name = "policies"
end
これが私の保存の試みです:
bar = Foo::Bar.new :client_id => 123
bar.valid? # => true
bar.client_id # => 123
bar.save # => ActiveResource::MissingPrefixParam...
これについての説明を何度も探しましたが、同じ指示しか見つかりません。
When a GET is requested for a nested resource and you don’t provide the prefix_param an ActiveResource::MissingPrefixParam will be raised.
にあるサーバーの API エンドポイントにアクセスしようとしてhttp://www.example.com/clients/[client_id]/policies
いますが、明らかに を提供できていclient_id
ないため、アプリは にリクエストを送信しますhttp://www.example.com/clients//policies
サーバーログには次のように表示されますActionController::RoutingError (No route matches "/clients//policies/" with {:method=>:post})
。