Help defining URL Rest structure for nested element

Yes, just remove the underscore. As the warning said, an underscore indicates you will not use the variable. It is a little bit more than a convention since you get warnings, but as you can see _params actually still does bind the variable. On the other hand, a _ by itself actually throws the variable away—trying to reference _ won’t work. But it’s convention to mostly name your throw-away variables so it’s clear what they are.

As far as list_rooms_by_house goes, if you want to list by house_id, you aren’t gaining anything by putting the into a %House{} struct like that. If you want to first ensure the house exists then fetch the house from the database. There are differing opinion here but as you have it, I would just change the function to list_rooms_by_house_id(house_id). You could also fetch the house and preload the rooms.

def get_house_with_rooms(id) do
  House
  |> Repo.get(id)
  |> Repo.preload([:rooms])

What you do heavily depends on how your app works so it’s hard to go over everything. But, for instance, if you have users that can only access certain houses, then putting house_id in a hidden field is a security concern. You would want to first load the house and ensure the user is allow to read/write it (whatever the permissions may be). Then I would have a create_room(house, rooms_attrs) function (whether that lives in a Houses or Rooms context is up to you and a different discussion). Merely putting the house_id in a hidden field would allow a user to change that to whatever id they wanted. If that’s not a security concern then it’s no big deal, but if it is then you definitely shouldn’t do this.