[英]How to fix Rails respond_with model that is not namespaced?
我正在用Rails构建API。 控制器使用Api::V1
命名空间,但模型则没有。 我正在添加responds_to :json
并将模型传递给respond_with
但是从模型生成路由时失败。 它应该是api_v1_resource_url
,但是它只是返回resource_url
。 我该怎么做才能解决此问题?
没有看到您的问题中的相关代码,请尝试以下操作:
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
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.