0

這個問題涉及this之一:滑軌控制器未初始化常數

我的形式:

</br> 
<%= 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 %> 

我的路線:

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

我的控制器:

class RaterController < ApplicationController 
    def index 
    end 

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

條我的路線與一個單一的資源:

rater_csv_rater GET /rater/rater_csv(.:format) raters#rater_csv 
    view_all_rater GET /rater/view_all(.:format)  raters#view_all 

我的路線與多個資源:

rater_csv_rater GET /rater/rater_csv(.:format) rater#rater_csv 
    view_all_rater GET /rater/view_all(.:format)  rater#view_all 

我真的困惑,爲什麼定義一個單一的資源raters#view_all

當我確定一個單一的資源:uninitialized constant RatersController 當我定義的多個資源:undefined local variable or method view_all_rater_path'`

回答

0

改變你的路線

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

仍然收到同樣的錯誤'未定義的本地變量或方法view_all_rater_path' – Yogzzz 2013-02-27 07:37:27

+0

'rake routes'輸出是什麼? – 2013-02-27 07:47:28

+0

'rater_csv_rater GET /rater/rater_csv(.:format)raters#rater_csv' 'view_all_rater GET /rater/view_all(.:format)raters #view_all' – Yogzzz 2013-02-27 07:55:58

0

在你的路由添加。

resources : raters 
+0

仍然得到爲什麼不使用命名空間'未定義的局部變量或方法'view_all_rater_path'。 (也重新啓動我的服務器) – Yogzzz 2013-02-27 07:31:11

+0

您實際上需要指定將'resource:raters'更改爲'resources:raters'。 – 2013-02-27 07:31:45

+0

你的路由將從'view_all_rater_path'改變爲'view_all_raters_path' – 2013-02-27 08:20:47

0

有了奇異的資源,你仍然需要一個多元化的控制器,所以這將是RatersController作爲錯誤說。

憑藉多元化的資源將是view_all_raters_path

0

,因爲你不使用任何航線評價者

namespace :raters do 
    get 'rater_csv' 
    get 'view_all' 
end 

而且控制器重命名爲Raters代替或Rater