0

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?

Drew Harris
  • 486
  • 1
  • 5
  • 13

2 Answers2

3

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

collection do
  get :somethingelse
end
member do
  get :people
end
basgys
  • 4,320
  • 28
  • 39
0

you can try this approach:

id = 1
User.find_by_sql(['select * from users where id = ?', id])`
Igor Kasyanchuk
  • 766
  • 6
  • 12