Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails 3-缺少索引路径?_Ruby On Rails_Routes_Rake - Fatal编程技术网

Ruby on rails Rails 3-缺少索引路径?

Ruby on rails Rails 3-缺少索引路径?,ruby-on-rails,routes,rake,Ruby On Rails,Routes,Rake,我的一个rails应用程序出现了一个非常奇怪的问题。我想我可能在做一些我无法识别的傻事。我的问题是,我似乎缺少大约一半的索引路径 例如,对于模型foo,如果我的控制器是“foos”,我将具有: foos POST /foos(.:format) {:action=>"create", :controller=>"foos"} 但无GET选项,通常为: foos GET /foos(.:format) {:action=>"index", :contro

我的一个rails应用程序出现了一个非常奇怪的问题。我想我可能在做一些我无法识别的傻事。我的问题是,我似乎缺少大约一半的索引路径

例如,对于模型foo,如果我的控制器是“foos”,我将具有:

foos POST   /foos(.:format)      {:action=>"create", :controller=>"foos"}
但无GET选项,通常为:

foos GET    /foos(.:format)   {:action=>"index", :controller=>"foos"}
下面我将向您展示我的实际代码,以帮助我恢复丢失的索引路由

routes.rb:

resource :announcements, :controller => "announcements" do
  resources :comments
  member do
    post 'vote'
  end
end
通告部分的路线:

announcements      POST   /announcements(.:format)      {:action=>"create", :controller=>"announcements"}
new_announcements  GET    /announcements/new(.:format)  {:action=>"new", :controller=>"announcements"}
edit_announcements GET    /announcements/edit(.:format) {:action=>"edit", :controller=>"announcements"}
                   GET    /announcements(.:format)      {:action=>"show", :controller=>"announcements"}
                   PUT    /announcements(.:format)      {:action=>"update", :controller=>"announcements"}
                   DELETE /announcements(.:format)      {:action=>"destroy", :controller=>"announcements"}
正如您所看到的,没有get/index。在我的控制器中,我定义了简单索引方法

def index
  @announcements = Announcement.all

  respond_to do |format|
    format.html
    format.xml  { render :xml => @announcements }  
  end
end
我真的不明白为什么我没有这个索引路径。这也发生在其他几个控制器上。任何帮助都将不胜感激


编辑:在控制台中,
app.announcements\u path
除了返回缺少索引路径的其他方法外,还返回一个缺少方法的错误。

这是因为您使用的是
resources
resource
)的单一版本。没有为这些生成
索引
操作路线。您应该将此更改为复数版本,并从行中删除
:controller

非常感谢,我知道我做了一些傻事。谢谢~哇,我也错过了那个。。。谢谢