看板 Ruby 關於我們 聯絡資訊
這麼久沒回(被放置 Play 了嗎XD),避免有其他人搞錯, 想想還是來解釋一下。 你的引述的程式碼片段只有在掛載 Rails Engine 並且使用其他 engine 的 URL helper 才有可能用到。 舉例來說當你在 routes.rb 這樣寫: Rails.application.routes.draw do mount Blog::Engine => "/blog" end 而你的 engine 長這樣: Blog::Engine.routes.draw do resources :posts end 有時候因為 URL helper 在不同的 engin 會撞名,所以會需要特別指定使用哪個 routes proxy: 所以會需要這樣寫: polymorphic_url([blog, post]) 當第一次使用 blog 時,會載入你引述的檔案, 至於哪裡會 method_missing,那就是 polymorphic_url 裡面的事了。 無論如何,還是想重申一次: 如果沒有掛載 engine,則 URL helper 和 method_missing 的用法是完全沒有關係的。 以上,與你分享 =) ※ 引述《JokerCatz (JokerCatz)》之銘言: : ccc~ 感謝,我一直以為是method_missing的實作,所以是method產生器 : 剛看了一下應該還是method missing類,只不過是即時generate,就不用二次字串分析 : 類似這種code : http://apidock.com/rails/ActionDispatch/Routing/RoutesProxy/method_missing : 簡單的來說初次使用還是method missing,之後產出該名method, : 然後因為method missing規則是需要設定到正式的method上而非自幹解決掉 : 就會call到你說的那邊去做產生就是 : &...另外的 RailsFun.tw 本身就是網址了 Orz" : ※ 引述《tonytonyjan (南洋大兜蟲)》之銘言: : : 我認為不是 method_missing 的用法 : : # actionpack/lib/action_dispatch/routing/route_set.rb:271 : : def define_named_route_methods(name, route) : : define_url_helper route, :"#{name}_path", route.defaults, name, PATH : : define_url_helper route, :"#{name}_url", route.defaults, name, FULL : : end : : 還是我誤會了你的意思? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.219.118.91 ※ 文章網址: http://www.ptt.cc/bbs/Ruby/M.1413473056.A.E5E.html ※ 編輯: tonytonyjan (61.219.118.91), 10/17/2014 01:20:26