I want to create a restful API where a user can go to foo.com/compani/users and they will get a list of all users from that company.
My routes.rb file has:
resources :schools do
resources :users
end
My models are:
class User < ActiveRecord::Base
belongs_to :school
end
class School < ActiveRecord::Base
has_many :users
end
However if i go to /schools/1/users I get ALL users for all schools (same list for 1, 2, 12314, etc). From what I understood I was supposed to get list of all users that have school_id of ‘1’. What am I missing?
if you nested the rescources correctly you should be able to do something like this: