9
I'm going through Michael Hartl's tutorial at http://ruby.railstutorial.org/. It's basically a message board app where Users can post Messages and others can leave Replies. Right now I'm creating Users. Inside the UsersController things look like this:
class UsersController < ApplicationController
def new
@user = User.new
end
def show
@user = User.find(params[:id])
end
def create
@user = User.new(params[:user])
if @user.save
flash[:success] = "Welcome to the Sample App!"
redirect_to @user
else
render 'new'
end
end
end
The author says that the following lines are equivalent. Which makes sense to me:
@user = User.new(params[:user])
is equivalent to
@user = User.new(name: "Foo Bar", email: "foo@invalid",
password: "foo", password_confirmation: "bar")
redirect_to @user redirects to show.html.erb. How exactly does that work? How does it know to go to show.html.erb?