RoR Response output type
I want my Rails rest application has json as default output format , also I want remove html format. Any suggestions开发者_运维问答? Thanks
Yes you can do it.
In your controller,
respond_to do |format|
#format.html # show.html.erb
#format.xml { render :xml => @post }
format.json { render :json => @post }
end
or you can handle it as javascript
respond_to do |format| format.js { render :json { :only => :name}.to_json end
then you just access your action with ".js" in the end
Try like this
format.any(:xml, :html, :json) { render :json => @post }
精彩评论