|
Step 6: Adding Session Support
Even though we implemented the user feature, a user cannot log in just yet. So, let’s add session support next.
You may have recognized the way we’ve created user accounts.
I’ve taken this general method from Railscast episode 250. That episode also demonstrates how to create session support, and I’ll use that approach for Ribbit.
We start by creating a controller to manage our sessions. We won’t actually store sessions in the database, but we do need to be able to set and unset session variables. A controller is the correct way to do that.- rails generate controller sessions new create destroy
复制代码 Here, we create a new controller, called sessions. We also tell it to generate the new, create, anddestroy methods. Of course, it won’t fill in these methods, but it will create their “shell” for us.
Now, let’s open the app/controllers/sessions_controller.rb file. |
|