【问题标题】:Rails 4 API - Nil location provided. Can't build URIRails 4 API - 提供零位置。无法构建 URI
【发布时间】:2015-01-24 07:41:51
【问题描述】:

我只想让我的 api 检查条目是否存在,然后返回/响应 truefalse (boolean)

控制器

def checkBus
    if Bus.exists?(:name => params[:driver_name])
        respond_with true
    else
        respond_with false
    end
end

但我收到此错误ArgumentError (Nil location provided. Can't build URI.)

【问题讨论】:

    标签: ruby-on-rails web-deployment server rails-api


    【解决方案1】:

    查看http://api.rubyonrails.org/v4.1.8/classes/ActionController/MimeResponds.html#method-i-respond_with

    您只能将respond_with 与资源一起使用。

    根据您的用例,一种选择是使用:

    render :text => 'true'
    

    【讨论】:

    • 很抱歉,但应该在哪里使用render
    【解决方案2】:

    你最好使用渲染:

    def checkBus
        if Bus.exists?(:name => params[:driver_name])
            render text: 'true'
        else
            render text: 'false'
        end
    end
    

    希望这可以帮助你:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多