new
and create
are part of CRUD.
new
action is used to render the new
view for the UserSessionsController
. In new
action you simply create an instance of UserSession
model class with @user_session = UserSession.new
. After this, new.html.***
(* is template handler like erb, haml, etc) is rendered where you will enter details of UserSession
object that you would like to be created. Upon submission of this form create
action would be invoked.
In create
action you collect the parameters passed from the new
view with @user_session = UserSession.new(params[:user_session])
and when you say @user_session.save
it actually creates a record in database table user_sessions
UPDATE
The new
action is invoked when you click on the Login Link. Why is it invoked? Because you have defined the login_path
in routes.rb
Since you are a beginner I would highly recommend you to:
- Read the Getting Started with Rails which will help you to understand the fundamentals of a Rails Application development.
- Then, I also recommend you to complete Learn Rails by Example By Michael Hartl.
- And finally, watch the Ruby on Rails Railscasts By Ryan Bates.
Although, you can search on Google and you will find many great resources for the Rails beginners but the above 3 are THE de facto ones.