开发者

ROR + Refactor default line of scaffolding in Single Line of Code

In Rails Controller, Using Scaffolding we generate default methods. Here One of the method is present. I wanna customized the last 4 lines into a single line. In my last project, I have done that today I am not able to memorize that single line of code.

  # Index
  def index
    @audits = Audit.all
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml =开发者_Python百科> @audits }
    end
  end

Here I have to refactor the below code in single line.

respond_to do |format|
  format.html # index.html.erb
  format.xml  { render :xml => @audits }
end

Thanks


you can use respond_with

respond_with @audits

and at the top of your controller define the formats you want with

respond_to :html, :json, :xml


respond_to { |format| format.html; format.xml { render :xml => @audits }; }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜