国产一区二区精品久久_蜜桃狠狠狠狠狠狠狠狠狠_午夜视频精品_激情都市一区二区

當前位置:首頁 > 網站舊欄目 > 學習園地 > 設計軟件教程 > 每天一劑Rails良藥之Cleaning Up Controllers with Post-back Actions

每天一劑Rails良藥之Cleaning Up Controllers with Post-back Actions
2010-01-14 07:04:48  作者:  來源:
我們習慣與one-action-per-request,但是我們(特別是初學者)很容易被controller里的new(),create(),edit()和update()這些方法弄暈。
其實我們可以用一個方法來代替them all:
Java代碼 復制代碼
  1. def edit   
  2.   @recipe = Recipe.find_by_id(params[:id]) || Recipe.new  
  3.   if request.post?   
  4.     @recipe.attributes = params[:recipe]   
  5.     redirect_to :main_url and return if @recipe.save   
  6.   end   
  7. end  

這證明了Ruby語言的強大和靈活
但和RESTful Rails Development不好合并,以為后者是對應到上述不同的方法的

安徽新華電腦學校專業職業規劃師為你提供更多幫助【在線咨詢