I am studying Michael Hartle's tutorial at http://ruby.railstutorial.org/ . This is basically a messaging app where users can post messages while others can post replies. Now I am creating Users
. Inside the UsersController
everything looks 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 the following lines are equivalent. What 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 it work? How to find out how to go to show.html.erb
?
source share