From the course: Ruby on Rails 5 Essential Training

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Create action: Create

Create action: Create - Ruby on Rails Tutorial

From the course: Ruby on Rails 5 Essential Training

Start my 1-month free trial

Create action: Create

- [Narrator] In this movie, we'll write the create action and learn to process form values. In the previous movie, we added the new action. New and create work together as a pair and together they make up the create portion of CRUD. New displays the form, create processes the form. Let's look at the four main steps in form processing. First, we need to instantiate a new object using the form parameters. Next, we attempt to save that object. If the save succeeds, we will redirect the user somewhere. In our case, we would redirect to the index action. If the save fails, then we want to re-display the form so that the user can fix the problems and resubmit the form. You might be wondering how the save could fail. We haven't put any data validation into our application yet but eventually we will. Data validation ensures the data received from the form matches the criteria of the data we want to allow to go in the database. For example, if we want to limit the subject's name to be a…

Contents