Search code examples
ruby-on-railsroutescustom-routes

Rails Routes get :this[:id]


I'm having problems with getting the correct route set up in my routes file. I have a controller for Events. Within the Events Controller I have an action called "people" which looks a little like this:

def people
    @people = Event.find_by_sql(["sql that joins three tables to get the data I need;", params[:id]])
end

In my routes I have:

resources :events do
    collection do
      get :somethingelse
      get :people
    end
end

If I hardcode my params[:id] before my "find_by_sql" it works just fine when I visit ".../events/people" However, if I try to do something like ".../events/5/people" I get the "No route matches [GET] "/events/5/people" error.

I am sure I am missing something simple in my routes file. Can anyone provide me with the part that I am missing?


Solution

  • Yes it's not on collection, it's on member

    collection do
      get :somethingelse
    end
    member do
      get :people
    end