You should take a look at the named routes feature in Ruby on Rails: https://guides.rubyonrails.org/routing.html#path-and-url-helpers
Creating a resourceful route will also expose a number of helpers to the controllers in your application. In the case of resources :photos:photos_path returns /photos
new_photo_path returns /photos/newedit_photo_path(:id) returns /photos/:id/edit (for instance, edit_photo_path(10) returns /photos/10/edit)photo_path(:id) returns /photos/:id (for instance, photo_path(10) returns /photos/10)
Each of these helpers has a corresponding _url helper (such as photos_url) which returns the same path prefixed with the current host, port, and path prefix.
So to be able to reach your controller, you have to add some routes to your routes.rb file and use it in your view:
# routes.rb resources :buildings resources :residents# index view<% @building.each do |b| %><div><%= link_to b.name, building_path(b) %></div><% end %># show view to show all residents, belonging to a building<% @building.residents.each do |resident| %><div><%= link_to resident.name, resident_path(resident) %></div><% end %>