ceth
ceth

Reputation: 45285

Return JSON to GET request

I need to get JSON to specific URLs in my application.

When I trying to get URL: .../api/test I get the error

ActionController::UnknownFormat

on the line:

respond_to do | format |

Why and how can I fix it ?

Upvotes: 1

Views: 56

Answers (1)

Roman Kiselenko
Roman Kiselenko

Reputation: 44360

Use simple render without respond_to block:

def test
  message = { :last_sync => "hi!" }
  render :json => message
end

respond_to block needs if you want render many different formats. Like html, json e.t.c in one action.

Upvotes: 2

Related Questions