关于ruby重构的过程中去除不必要的format

 (文章是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com)

#这段话可以由下面的话替代
56     respond_to do |format|
57       if @video.save
58         format.html { redirect_to(:action => "index", :forminfo => @subject) }
59       else
60         format.html { render :action => "new" }
61       end
62     end
63     #用于替代上面的方法
64     if @video.save
65       redirect_to(:action => "index", :forminfo => @subject)
66     else
67       render :action => "new"
68     end

#以下的方法可以由下面的方法替代
102 respond_to do |format|
103 format.html { redirect_to(:action => 'index', :forminfo => @subject) }
104 format.xml { head :ok }
105 end
106 #用于替代上面的方法
107 redirect_to(:action => 'index', :forminfo => @subject)

原文地址:https://www.cnblogs.com/iwangzheng/p/3578076.html