开发者

respond_with json oddness

开发者 https://www.devze.com 2023-02-15 04:00 出处:网络
respond_to :json def create 开发者_如何学Pythonrespond_with(\'test\') end I was just doing some testing and the above gives me an error of:
 respond_to :json

  def create
  开发者_如何学Python  respond_with('test')
  end

I was just doing some testing and the above gives me an error of:

undefined method `test_url' for #

Why is it trying to turn test into a url? Is this a bug?


A JSON object must have two octets, as in a key and a value. You can't just send through a string.

Try this instead:

respond_with(:message => "test")


I had a similar error (respond_with threw an undefined method `test_url' error) when test was a class and my routes didn't contain a resource entry.

respond_to :json

def method
  if request.post?
    @test = Test.create
    respond_with @test
  end
  ...
end

Adding a resource entry to my routes.rb fixed the problem

resources :test
0

精彩评论

暂无评论...
验证码 换一张
取 消