我有一个嵌套的 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})
.