Skip to content


Subversion checkout URL

You can clone with
Download ZIP
tree: 1c583d07af
Fetching contributors…

Cannot retrieve contributors at this time

70 lines (37 sloc) 2.156 kb

Action View Overview

In this guide you will learn:

  • What Action View is, and how to use it


What is Action View?


Using Action View with Rails


Using Action View outside of Rails


Templates, Partials and Layouts


Using Templates, Partials and Layouts in “The Rails Way”


Partial Layouts


View Paths


Overview of all the helpers provided by AV


Localized Views

Action View has the ability render different templates depending on the current locale.

For example, suppose you have a Posts controller with a show action. By default, calling this action will render app/views/posts/show.html.erb. But if you set I18n.locale = :de, then app/views/posts/ will be rendered instead. If the localized template isn’t present, the undecorated version will be used. This means you’re not required to provide localized views for all cases, but they will be preferred and used if available.

TODO add full code example…

You can use the same technique to localize the rescue files in your public directory. For example, setting I18n.locale = :de and creating public/ and public/ would allow you to have localized rescue pages.

Since Rails doesn’t restrict the symbols that you use to set I18n.locale, you can leverage this system to display different content depending on anything you like. For example, suppose you have some “expert” users that should see different pages from “normal” users. You could add the following to app/controllers/application.rb:

before_filter :set_expert_locale

def set_expert_locale
I18n.locale = :expert if

Then you could create special views like app/views/posts/, which would only be displayed to expert users.

You can read more about the Rails Internationalization (I18n) API here.


Lighthouse Ticket

  • April 5, 2009: Starting work by Trevor Turk, leveraging Mike Gunderloy’s docs
Jump to Line
Something went wrong with that request. Please try again.