我正在使用Rails构建一个API。控制器使用Api::V1命名空间,但模型不是。我正在添加responds_to :json并将模型传递给respond_with,但在从模型生成路由时失败。它应该是api_v1_resource_url,但它只是返回resource_url。我能做些什么来解决这个问题呢?
发布于 2015-06-21 14:49:58
在您的问题中没有看到相关代码的情况下,尝试这样做:
respond_with(:api, @yourmodel)
我假设您的代码类似于以下代码:
def Api::V1
responds_to :json
def create
@yourmodel = YourObject.new(params[:yourmodel])
@yourmodel.save
respond_with(:api, @yourmodel) // TRY THIS
end
endhttps://stackoverflow.com/questions/30961981
复制相似问题