我正在尝试从教程中学习如何使用 Rails 作为 iPhone 应用程序的后端。看来我很早就失败了。教程说,在我创建脚手架“目标”后,我应该将 JSON 处理添加到目标控制器操作中的 respond_to 块:
def index
  @goals = Goal.all
  respond_to do |format|
    format.html
    format.xml  { render :xml => @goals }
    format.json { render :json => @goals }
  end
end
顺便说一句,这就是我的脚手架控制器之前的填充方式:
  def index
    @goals = Goal.all
    respond_to do |format|
      format.html # index.html.erb
        format.json { render json: @goals }
    end
  end
当我想使用 json 格式请求资源时会发生错误(是的,我已经用数据填充了表格):
$ curl http://localhost:3000/goals/1.json
curl: (7) couldn't connect to host
我的问题: 1. 如果已经有一些 json 代码(即使使用不同的语法),这一步对我来说是否必要?2.如何解决问题?我只是按照说明进行操作,仅此而已...
一些附加说明:本教程涉及 Rails 3.0,我的机器上有 Rails 3.2。有一些语法差异吗?