开发者

respond_with json oddness

 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜