Rails controller path not found

那年仲夏 提交于 2019-12-24 08:20:55

问题


My form tag in my view:

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

My controller action:

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

My routes:

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

When I navigate to /rater/view_all I get a No route matches {:action=>"view_all", :controller=>"rater"}


回答1:


The problem here is going to be singular vs. plurals in your route definitions.

Your routes gives the following output for 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

Because you've defined a plural resource (resources) with a singular name (rater).

If you make it a singular resource (resource) the routes will clear themselves up.

And always always remember to use rake routes!




回答2:


Did you try "rake routes" on the console to see the structure of your routes?




回答3:


2 everybody: Make sure that you are calling right request, GET or POST as needed.



来源:https://stackoverflow.com/questions/15102941/rails-controller-path-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!