views episodes
#7
Mar 19
7 comments
All About Layouts
Everything you wanted to know about layouts: global layouts, controller layouts, shared layouts, dynamic layouts and action layouts. Yes, there really are that many ways to specify a layout.
Layouts and content_for
If you want to change something in the layout on a per-template basis, content_for is your answer! This allows templates to specify view code that can be placed anywhere in a layout.
HABTM Checkboxes
It is often asked: how do I create a list of checkboxes for managing a HABTM association? Ask no more because this episode will show you how to do exactly that.
Looping Through Flash
Displaying flash messages in the layout can be a pain at times. In this episode you will learn an easy way to display any kind of flash message by looping through the hash.
Cross Site Scripting
Another common security issue is cross site scripting. In this episode you will see why it is so important to escape any HTML a user may submit.
in_groups_of
Have you ever wanted to visually line up items in rows and columns? The in_groups_of method makes this a cinch. Just watch out for the gotcha.
group_by Month
Learn how to use the very useful group_by method to group an array by anything you want! In this episode I group an array of tasks by month then sort it properly.
Pretty Page Title
If you are like me, you avoid creating page titles because it is kind of a pain. But in this episode I will show you a clean way to add titles to your pages.
Formatting Time
Learn how to use the trusty strftime method to format a time, and see how Rails allows you to save this format for later use.
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.
Simple Search Form
A search form is quite different than other forms, this is because it does not deal with model's attributes. See a good way to add a simple search form 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.
Customize Field Error
When a validation error occurs, Rails helpfully wraps the field in a div tag so you can style it. But sometimes you don't want this behavior. In this episode you will see how to customize it.
Blocks in View
If you try to create a helper method which accepts a block, you will run into a few gotchas. Learn the secrets of blocks in views 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.
Cleaning Up the View
This episode starts off with a big, messy template. Watch as this code shrinks and becomes more readable while the interface stays the same.
Create Model Through Text Field
Let's say you provide a select menu for setting which category a given product belongs to, but you also want the option of creating a new category by typing the name in a text field. See a great way to do that in this episode.
Model Name in URL
By default, Rails uses the model's id in the URL. What if you want to use the name of the model instead? You can change this behavior by overriding the to_param method in the model. Watch this episode for details.
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.
Markaby in Helper
Do you ever need to generate HTML code in a helper method? Placing it directly in Ruby strings is not very pretty. Learn a great way to generate HTML through Markaby in this episode.
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.
Complex Forms Part 2
See how to use Javascript and RJS to add and remove form fields dynamically. This episode will build upon the previous episode allowing you to create any number of tasks in one form the same time a project is created.
Complex Forms Part 3
In this third and final episode on complex forms I will show you how to edit a project and multiple tasks all in one form. This includes removing and adding tasks dynamically as well. See the show notes for updated code.
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.
Simplify Views with Rails 2.0
Rails 2.0 is almost here. One of the many features in this release is the smarter helper methods which can make your views much cleaner. Learn all about it in this Episode.
Generating RSS Feeds
See how to easily generate and link to an RSS feed using new features in Rails 2.0. Watch this episode or details.
Dynamic Select Menus
See how to dynamically change a select menu based on another select menu using Javascript. In this episode everything is kept client side which leads to a more responsive user interface.
Fragment Caching
Sometimes you only want to cache a section of a page instead of the entire page. Fragment caching is the answer as shown in this episode.
Complex Partials
How do you handle partials which have differences depending on the action which is rendering them? Here's three suggestions for this problem.
5 View Tips
Here's five quick tips to use in views. Be sure to catch the end of the episode where I reveal an exciting contest!
Refactoring Out Helper Object
If you have complex view logic, this can easily lead to helper methods which call each other. See how to refactor this out into another object 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.



