我們習慣與one-action-per-request,但是我們(特別是初學者)很容易被controller里的new(),create(),edit()和update()這些方法弄暈。
其實我們可以用一個方法來代替them all:
這證明了Ruby語言的強大和靈活
但和RESTful Rails Development不好合并,以為后者是對應到上述不同的方法的
其實我們可以用一個方法來代替them all:
- def edit
- @recipe = Recipe.find_by_id(params[:id]) || Recipe.new
- if request.post?
- @recipe.attributes = params[:recipe]
- redirect_to :main_url and return if @recipe.save
- end
- end
這證明了Ruby語言的強大和靈活
但和RESTful Rails Development不好合并,以為后者是對應到上述不同的方法的
安徽新華電腦學校專業職業規劃師為你提供更多幫助【在線咨詢】