【发布时间】:2012-06-04 18:58:20
【问题描述】:
我有一个嵌套的 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.
我正在尝试在http://www.example.com/clients/[client_id]/policies 访问我们服务器的 API 端点,但我显然未能提供 client_id,因此我的应用程序向 http://www.example.com/clients//policies 发出请求
服务器日志告诉我:ActionController::RoutingError (No route matches "/clients//policies/" with {:method=>:post})。
【问题讨论】:
标签: ruby-on-rails-3.2 activeresource ruby-1.9.3