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

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -