Question

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?

Was it helpful?

Solution

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

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

OTHER TIPS

you can try this approach:

id = 1
User.find_by_sql(['select * from users where id = ?', id])`
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top