2011-05-26 64 views
0

也沒有路由匹配這是視圖中的代碼。即使將路由添加到routes.rb

<% form_tag({:controller => 'users', 
        :action => 'test'}) do %> 
     <%= text_field_tag(:search_options, params[:search_options])%> 
     <%= submit_tag("Display text!")%> 
     <% end -%> 

我有一個文件test.html.erb並還增加了獲取「用戶/測試」的routes.rb還是我得到錯誤:沒有路由匹配「/用戶/測試」

+0

的'耙routes'命令可用於調試這些問題有所幫助。我建議添加'rake routes |的輸出grep user'到你的問題中,並在'users_controller'中定義的動作列表 – andrewmitchell 2011-05-26 07:49:04

回答

2

form_tag方法默認創建一個使用HTTP POST發送的表單。您聲明您在routes.rb中定義的路線是GET。所以,你有兩個選擇來解決這個問題:

  1. 路線更改爲POST "users/test"
  2. form_tag電話更改爲:form_tag({:controller => 'users', :action => 'test'}, :method => :get)
相關問題