ruby on rails - Return JSON to GET request -
I need to get JSON on a specific URL in my application.
-
I generates controller API
-
I've added my controller the 'test' method:
Answer DIF Exam. Format | Format | Message = {: last_sync = & gt; "Hello!" } Format.json {Render: Jason = & gt; Message} End
-
I have added the route:
# api section 'api / test' = & gt; 'API # test'
-
When I try to get the URL: ... / API / Test me Error:
ActionController :: UnknownFormat
On this line:
Answer_to Format |
Why and how can I fix this?
Use simple response_to
Render without block:
DIF test message = {: last_sync = & gt; "Hello!" } Render: json = & gt; Message ending
response_to
block is needed if you want to submit several different formats like html, json etc
In action.
Comments
Post a Comment