Use a before_action controller filter to determine if a user has been previously authenticated and therefore authorized to access a page. If the user is not authorized, they will be redirected to the login form.
- [Instructor] In the last movie,…we used the session to store the user ID…whenever a user logs in,…but we don't have any code that checks…that the user ID is present to determine whether…a user should be granted access to a page or not.…To go back to our metaphor,…it's like we've given them a hand stamp,…but there's no one at the concert door…checking for hand stamps.…Let's add a before action to confirm…that the user has been authenticated.…Inside our access controller,…we're going to put, right after our layout admin,…before action, and then we're…going to call it confirm logged in.…
We will copy that confirmed logged in,…were going to drop down to the bottom of the page,…and remember, we want to make this a…private method called confirmed logged in.…What is that method going to do?…Well, we're going to check and see…if the session ID is there.…We can use unless for that, that's if not,…that's the same thing as having if not,…unless there is a session ID, meaning if there…is a session ID, don't do anything,…Meaning that if there is a session ID, don't do anything,…
- Creating and configuring a new Ruby on Rails project
- Generating controllers and views
- Handling server requests
- Using different types of routes
- Rendering and viewing templates
- Generating migrations and models
- Creating, updating, and deleting records
- Finding records with queries
- Understanding relationship types
- Writing controllers for CRUD
- Working with layouts and helpers
- Managing application assets
- Building forms
- Validating data
- Authenticating users
Skill Level Beginner
1. What Is Ruby on Rails?
2. Get Started
3. Controllers, Views, and Dynamic Content
4. Databases and Migrations
5. Models and ActiveRecord
7. CRUD, REST, and Resourceful Routes
8. Controllers and CRUD
9. Layouts, Partials, and View Helpers
12. Data Validation
13. Controller Features
14. User Authentication
15. Improve the Simple CMS
Next steps1m 44s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.