簡體   English   中英

如何修復未命名空間的Rails response_with模型?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM