看板 Ruby 關於我們 聯絡資訊
環境: e.g. Ruby 1.8.7 Rails 2.2.2 大家好 想請教link_to 跟 button_to的不同 小弟在首頁寫了 <%= button_to "發表文章", :action => 'new' %> 接著在controller寫了 def new if request.post? Article.add_article(params[:title],params[:content]) redirect_to :action => 'index' end end 本以為在首頁按下按鈕 可以進入新頁面並且填寫文章 之後再使用submit_tag即可 沒想到按下按鈕 頁面不會跳轉 而會在原地跳 將button_to改成link_to才會正常運行 查了資料發現button_to用了HTTP POST link_to用了HTTP GET 想知道為什麼要有這樣的差異? 使用時機為何? 我本以為button跟link是一模一樣的 謝謝! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.166.196.50 ※ 編輯: poopoo888888 來自: 218.166.196.50 (12/05 21:47)
hellolucky:先去研究HTML a tag 和input type="button"的差別吧 12/06 22:53
poopoo888888:我知道了 謝謝! 12/08 23:50
hellolucky:加油吧!!!下禮拜三有Ruby Tuesday 可以來認識一些高手 12/09 00:34