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 - Ruby on Rails Tutorial
From the course: Ruby on Rails 5 Essential Training
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
-
Read action: Index6m 31s
-
Read action: Show5m 22s
-
Form basics5m 13s
-
Create action: New4m 54s
-
Create action: Create5m 27s
-
Strong parameters6m 33s
-
Update actions: Edit/update7m 53s
-
Delete actions: Delete/destroy7m 11s
-
Flash hash7m 28s
-
Challenge: Pages and sections CRUD1m 43s
-
Solution: Pages and sections CRUD7m 38s
-
-
-
-
-
-
-
-
-