Ruby on Rails: How do detect if access by JSON?

前端 未结 6 551
旧时难觅i
旧时难觅i 2021-02-03 23:43

I got a GET URL that calls a controller method getInfo. It can be called by mydomain.com/getInfo.json?params=BLAHBLAH or mydomain.com/getInfo?params=BLAHBLAH

In the cont

6条回答
  •  梦谈多话
    2021-02-03 23:55

    Yes. Within the controller you can call the request.format method to determine the format requested by the user.

    If you need more than just the format, you can look at request.url for the full URL. More details about the request object can be found here.

提交回复
热议问题