Rails 4 API - 未提供位置。无法构建 URI
Rails 4 API - Nil location provided. Can't build URI
我只是想让我的 api 检查条目是否存在,然后 returns/responds 使用 true
或 false
(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.)
查看http://api.rubyonrails.org/v4.1.8/classes/ActionController/MimeResponds.html#method-i-respond_with
您只能将 respond_with
与资源一起使用。
根据您的用例,一种选择是使用:
render :text => 'true'
你最好使用渲染:
def checkBus
if Bus.exists?(:name => params[:driver_name])
render text: 'true'
else
render text: 'false'
end
end
希望对您有所帮助:)
我只是想让我的 api 检查条目是否存在,然后 returns/responds 使用 true
或 false
(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.)
查看http://api.rubyonrails.org/v4.1.8/classes/ActionController/MimeResponds.html#method-i-respond_with
您只能将 respond_with
与资源一起使用。
根据您的用例,一种选择是使用:
render :text => 'true'
你最好使用渲染:
def checkBus
if Bus.exists?(:name => params[:driver_name])
render text: 'true'
else
render text: 'false'
end
end
希望对您有所帮助:)