简体   繁体   中英

How do I access my json data that I have created in rails

What url can I enter to see the json value and how do I get my iphone project to access it.

Here is my index method

def index
        @players = Player.find(:all)
        respond_to do |format|
            format.html
            format.json  { render :json => @players.to_json }
        end
    end

here is my routes.

ChooseTeams::Application.routes.draw do
  resources :players
 root :to => "players#index"
end

Please ask for any additional information as I'm new in rails and not sure what else to provide here.

to index method: localhost:(port)/players.json (Method GET)

to show method: localhost:(port)/players/1.json (Method GET)

I recomend to you POSTMAN(in Google Chrome) to test this respond.

To respond to iPhone JSON use REST API

http://railscasts.com/episodes/350-rest-api-versioning

You should set the accept headers when requesting the URL:

curl -H 'Accept: application/json' http://localhost:<PORT>/players

In your iOS project, you should set whatever HTTP library you're using to set the above header.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM