找不到 Rails 控制器路径 [英] Rails controller path not found

查看:58
本文介绍了找不到 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

当我导航到/rater/view_all 时,我得到一个 No route matching {:action=>"view_all", :controller=>"rater"}

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

推荐答案

这里的问题将是你的路由定义中的单数还是复数.

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

您的路线为 rake 路线 提供以下输出:

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

因为你定义了一个复数资源(resources)和一个单数名称(rater).

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

如果您将其设为单一资源 (resource),路由将自行清理.

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

永远记住使用rake routes

这篇关于找不到 Rails 控制器路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆