Reputation: 99
Can I have such a thing in Phoenix as long as nested resource is concerned
resources "/landlords", LandlordController do
resources "/houses", HouseController do
resources "/units", UnitController
end
end
Where I have landlord has_many houses and house also has_many units. Or any idea how this can be achieved?
Upvotes: 1
Views: 408
Reputation: 99
I was able to make it work by doing this
resources "/landlords", LandlordController do
resources "/houses", HouseController
end
resources "/houses", HouseController do
resources "/units", UnitController
end
Upvotes: 0
Reputation: 5812
Yes, it's possible and it's quite common. This is the best to achieve that. Please read a doc to get more information and there's also example how routes look like in such case.
resources "/users", UserController do
resources "/posts", PostController
end
generate routes
user_post_path GET /users/:user_id/posts PostController :index
user_post_path GET /users/:user_id/posts/:id/edit PostController :edit
user_post_path GET /users/:user_id/posts/new PostController :new
user_post_path GET /users/:user_id/posts/:id PostController :show
user_post_path POST /users/:user_id/posts PostController :create
user_post_path PATCH /users/:user_id/posts/:id PostController :update
PUT /users/:user_id/posts/:id PostController :update
user_post_path DELETE /users/:user_id/posts/:id PostController :delete
Upvotes: 1