开发者

Rails 3 - Missing Index Paths?

I'm having a pretty weird problem with one of my rails apps. I think I'm probably doing something really silly that I just haven't been able to identify. My problem is that, I seem to be missing about half of my index paths.

For example, if my controller is "foos" for a model foo, I'll have the:

foos POST   /foos(.:format)      {:action=>"create", :controller=>"foos"}

But no GET option which would usually be as:

foos GET    /foos(.:format)   {:action=>"index", :controller=>"foos"}

Below I'll show you my actually code, to help me recover my missing index routes.

routes.rb:

resource :announcements, :controller => "announcements" do
  resources :comments
  member do
    post 'vote'
  end
end

routes for the announcements part:

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"}

As you can see there is no get / index. In my controller, I have the simply index method defined...

def index
  @anno开发者_如何学运维uncements = Announcement.all

  respond_to do |format|
    format.html
    format.xml  { render :xml => @announcements }  
  end
end

I really don't understand why I don't have this index path. It's happening on several other controllers as well. Any help would be appreciated.

Edit: In the console, app.announcements_path returns a method missing error, in addition to the others that have missing index paths.


This is because you're using the singularized version of resources (resource). There is no index action route generated for these. You should change this to be the pluralized version, and remove :controller from the line too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜