controllers episodes
#13
Apr 02
8 comments
Dangers of Model in Session
Be careful when storing a model in a session. It will behave differently than you expect and can easily get out of sync with the database. Instead of storing the model directly in the session, store the id to the model and use that to fetch it from the database.
Named Routes
When you add a custom route, make it a named route so you have url helper methods to easily link to that new route. See episode for details.
Custom REST Actions
REST adds many constraints. It restricts your controllers to seven actions. Normally this is okay, but sometimes you need to add your own custom actions. Learn how in this episode.
Multibutton Form
If you have a form with multiple buttons, you can detect which button was clicked by checking the passed parameters. Learn how in this episode.
Catch-all Route
Sometimes you need to add complex/dynamic routes. This is often impossible to do in routes.rb, but do not worry. It can be accomplished with a catch-all route. See how in this episode.
Update through Checkboxes
See how to select multiple items using checkboxes and perform an action on the selected items in this episode.
Handling Exceptions
When an exception is raised in development you get the full error along with the stack trace. In production, only a simple message is displayed. Learn why this is and how to customize the handling of exceptions.
Custom Helper Modules
Rails designates one helper module per controller, but that shouldn't stop you from making custom helper modules to help structure the code. Learn how in this episode.
restful_authentication
Need multiple user authentication? If so, the restful_authentication plugin is a great way to go. It will generate some basic authentication code for you which is good starting point to your authentication system. Watch this episode for details.
OpenID Authentication
Ever wonder how to implement OpenID authentication in your Rails app? This episode will show you how to add it to a site with an existing authentication system.
Custom Routes
In this episode you will learn how to add custom routes, make some parameters optional, and add requirements for other parameters.
Testing Controllers with RSpec
Controllers are tricky to test, and there's no perfect way to do it. In this episode you will see how I test controllers, and my reasoning behind it.
Complex Forms Part 1
Complex forms often lead to complex controllers, but that doesn't have to be the case. In this episode see how you can create multiple models through a single form while keeping the controller clean.
Destroy Without JavaScript
If the user has JavaScript disabled, the "Destroy" link might not work properly. In this episode I will explore a number of ways to work around this issue.
Generating PDF Documents
In this episode I will show you how to create PDF documents using the excellent PDF::Writer gem.
HTTP Basic Authentication
Rails 2.0 offers an extremely easy way to do HTTP basic authentication. See how in this episode.
Page Caching
Page caching is an efficient way to cache stateless content. In this episode I will show you how to cache the dynamic javascript we created last week.
Action Caching
Action caching behaves much like page caching except it processes the controller filters. You can also make it conditional as seen in this episode.
Site Wide Announcements
Sometimes you need to display an administrative announcement to every page on the site and give the users the ability to hide the announcement. See how in this episode.



