I'm looking at this tutorial: https://www.railstutorial.org/book/sign_up
We get on to rails resources.
config/routes.rb
Rails.application.routes.draw do
root 'static_pages#home'
get 'help' => 'static_pages#help'
get 'about' => 'static_pages#about'
get 'contact' => 'static_pages#contact'
get 'signup' => 'users#new'
resources :users
end
app/controllers/users_controller.rb
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
end
def new
end
end
app/views/users/show.html.erb
<%= @user.name %>, <%= @user.email %>
There is also this handy table of telling us how ruby will handle the various requests to the Users
resource.
I have two questions here.
How does RoR know when accessing the
/users
,/users/1
etc urls, what to actually use theindex
,show
methods.More importantly, - when the
show
method is called, how it does it know the give theshow.html.erb
view to browser? What if I wanted to return a different view?