0
下面是我的路線文件中定義的路線:可以直接導航到路由路徑,但不能通過單擊鏈接導航?
#routes for colleges
get "colleges/universityofconnecticut"
get "colleges/ferrisstateuniversity"
#routes for states
get "pages/connecticut"
get "pages/michigan"
#root route
root :to => "pages#home"
這裏是我創建了一個下拉菜單。請注意,使用路線:
<form>
<select name="URL" onchange="window.location.href= this.form.URL.options[this.form.URL.selectedIndex].value">
<option><%= link_to 'Connecticut', pages_connecticut_path %></option>
<option> <%= link_to 'Michigan', pages_michigan_path %></option>
</select>
</form>
當我點擊下拉鍊接,我收到在瀏覽器中的錯誤是「沒有路由匹配/密歇根州」和「無路由匹配/康涅狄格」。但是,我可以輸入到我的瀏覽器本地主機:3000 /頁/康涅狄格,它會工作。
任何想法爲什麼會發生這種情況?
編輯:這裏是結果「耙路線」
colleges_universityofconnecticut GET /colleges/universityofconnecticut(.:format) {:controller=>"colleges", :action=>"universityofconnecticut"}
colleges_ferrisstateuniversity GET /colleges/ferrisstateuniversity(.:format) {:controller=>"colleges", :action=>"ferrisstateuniversity"}
pages_connecticut GET /pages/connecticut(.:format) {:controller=>"pages", :action=>"connecticut"}
pages_michigan GET /pages/michigan(.:format) {:controller=>"pages", :action=>"michigan"}
root /(.:format) {:controller=>"pages", :action=>"home"}
你能粘貼'耙routes'的結果呢? – zeroed
剛做過@zeroed –
看到這個問題:http://stackoverflow.com/questions/2944977/how-to-redirect-to-another-page-using-a-select-menu-and-link-to-ruby- on-rail – siekfried