From the course: Ruby on Rails 6 Essential Training: Models and Associations
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Challenge: Callbacks - Ruby on Rails Tutorial
From the course: Ruby on Rails 6 Essential Training: Models and Associations
Challenge: Callbacks
(upbeat music) - [Instructor] It's time for another challenge assignment. This one will give you the opportunity to use what you've just learned about callbacks. There are three tasks in this challenge assignment. The first is, I want you to add a callback to both the Subject and Page models, which will set the name attribute to be name.titleize before the record is validated. Name.titleize is going to put the name into title case. So, it's going to ensure that even if the user puts in something that's in all lowercase, it'll get titleized before it's validated, and then saved. The second task is to modify the Subject callback :log_save, one that we already wrote in a previous movie, but make it so that it only executes if the subject has any visible pages. And then, third, from the Rails console, find the subject record that has the position 1, and change its visibility without triggering any callbacks. I think you'll be…
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.