开发者

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 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜