简体   繁体   中英

Using Params with API calls via a GET request

I am developing an api for an iOS application. I currently have a Property class that has many Issues. In the API controller for Index I have the following code:

def index
    @issues = @property.issues
end

I am setting the @property var with a before_action

I currently have this in my routes file inside my API wrapper routes:

  resources :issues do 
    resources :comments
  end

It is obviously putting the proper REST verbs for to the calls, but my issue is I am in need of passing the parameter of property_id in order for my before action to find Property.where(id: pay ams[:property_id] .

  1. Can I pass parameters at all during a GET request to rails 4.
  2. Do I need to do it in the URL with ?property_id=1 or in the request header?
  3. Do I need to specify parameters in the routes file for this GET request?
  4. In Rails 4, would the strong parameters take place and I need to pass a body of:

     { "issue":["property_id":2] } 
  1. Yes you can pass on parameters to GET requests
  2. Do it with ?pid=4
  3. No, you dont have to specify it in routes.
  4. Not clear.

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