I’m trying to learn from a tutorial how to use Rails as Backend for an iPhone Application. And it seems I fail at a very early beginning.
The tutorial says after I created the scaffold “Goal”, I should add JSON handling to the respond_to blocks in the actions of the GoalsController:
def index
@goals = Goal.all
respond_to do |format|
format.html
format.xml { render :xml => @goals }
format.json { render :json => @goals }
end
end
by the way, that’s how my scaffolded controller was filled before:
def index
@goals = Goal.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @goals }
end
end
the error happens when I want to request resource with a json format (yes, I already filled the table with data):
$ curl http://localhost:3000/goals/1.json
curl: (7) couldn't connect to host
My questions:
1. Is this step necessary for me if there’s already some json-code (even with different syntax)?
2. how to solve the problem? I just followed the instructions and nothing more…
some additional note: The tutorial deals with Rails 3.0 and I have Rails 3.2 on my machine. Are there some syntax-differences?
Did you start your rails server yet by running
rails s? It seems you haven’t started your rails server yet. After running this command, you should be able to see the incoming requests in your terminal.The other thing is that your code is about
indexaction, while you made request to theshowaction.