Rails 3.1 action caching and render layout false

Today I ran into one of the weirdest issues I ever ran into the past 6 years.

In Alchemy CMS we use rails action caching to cache the content of pages. This worked fine for rails 2.x. But now we finally made the switch to rails 3.1 we had an weird issue with action caching.

Although we passed :layout => false to caches_action the whole layout was always cached together with the action. After nearly 5 hours of debugging and swearing I found the solution.

In the show action (the action we are caching, obviously) we call

render :layout => layout_for_page

(layout_for_page returns either application.html.erb if present, or alchemy/pages.html.erb if not).

After removing this everything worked fine. But how do we ensure our feature is still working?

I use the layout class method and pass the method name as symbol:

layout :layout_for_page

Rails evaluates this method and uses the return value as layout.

HTML5 Forms Placeholder Fallback

Today I made a HTML5 Form with the new cool placeholder feature.

The placeholder feature lets you set a placeholder text for an form input element.

<input type="text" placeholder="Your name" name="name">

See more here

But like often in this shiny new HTML5 world the browser support for HTML5 is limited.

So I wrote a jQuery based Javascript fallback for browsers not supporting this feature.