Rails的控制器未找到路径

问题描述:

我的形式标记在我看来:Rails的控制器未找到路径

<%= form_tag view_all_rater_path, :method => 'get' do %> 
    <p> 
    <%= text_field_tag :search, params[:search], :placeholder => 'Search by Set # or date' %></br> 
    <%= submit_tag "Search", :class => "btn btn-link", :name => nil %> 
    </p> 
<% end %> 

我的控制器动作:

def view_all 
    if params[:search] 
     @ratings = RatingSet.find(:all, :conditions => ['id = ? or rating_date like ?', "%#{params[:search]}%"]) 
    else 
     @ratings = RatingSet.all 
    end 
    end 

我的路线:

resources :rater, :only => [:index] do 
    collection do 
     get :rater_csv 
     get :view_all 
    end 
    end 

当我浏览到/评价者/ view_all我得到一个No route matches {:action=>"view_all", :controller=>"rater"}

这里的问题将在你的路由定义中与单数相比。

你的路线给出了rake routes以下的输出:

rater_csv_rater_index GET /rater/rater_csv(.:format)         rater#rater_csv 
view_all_rater_index GET /rater/view_all(.:format)         rater#view_all 
      rater_index GET /rater(.:format)           rater#index 

因为你定义了一个奇异的域名(rater)复数资源(resources)。

如果您将它作为单一资源(resource),路线将自行清除。

并始终记得使用rake routes

+0

当我运行耙路线后改变了我的路线,以一个单一的资源,我得到:'rater_csv_rater GET /rater/rater_csv(.:format)评价者#rater_csv view_all_rater GET /rater/view_all(.:format)评价者#view_all ' – Yogzzz 2013-02-27 06:51:10

+0

而且这与您在视图中使用的路线相匹配。 – sevenseacat 2013-02-27 08:41:19

Did您可以在控制台上尝试“耙路”以查看路线的结构?