1

URI の conneg やファイルのような拡張子 (例: ) に関係なく、JSON のみを返したいモデルがあります/app/model.json。Google-fu は不足していますが、これはそれほど難しくありません。

4

2 に答える 2

5

In your controllers you simple have to create a respond_to block that only responds to JSON:

respond_to do |format|
  format.json { render :json => @model }
end
于 2013-08-14T20:31:47.360 に答える
0

This is actually a decision made by the controller, not because there is/is not a model or view present. In your controller you can:

render json: @your_model

However you will quickly find that the default implementation of to_json (which is what is used internally, above) can be annoying hard to do exactly what you want. When you reach that point you can use RABL to create views that massage the JSON from your model(s) exactly as you want.

于 2013-08-14T20:32:13.543 に答える