Advertising in RSS Feeds BEA endorses Spring
Jun 27

The Flash. The Rails one, not the Macromedia/Adobe one

Ruby, Tech Add comments

There are lots of features in Rails that make you think “yeah, I really have wanted just that”. Often, it isn’t that you couldn’t get the same affect in [insert your favourite web framework here], but you got it as a hack.

One of the small features that made me smile was the flash that Rails has.

As Dave mentions in his new, excellent, Rails book:

The contents of the flash are available to the next request in this session before being deleted automatically.

You just access the flash in your controller a la:

flash[:error] = “Doh. I thought I saw a pussy cat”

and then in the view simply:

<% if @flash[:error] -%>

Error: <%= @flash[:error] %>

<% end -%>

Side Note

How nice is it that you can use -%> to suppress newlines. No more pages of empty lines in your damn voice source (a pain in J/ASP land).

So, sure, you can write a filter to do this stuff, and it is a small thing. But with Rails it is all just there.

Thanks for thinking of me :)

4 Responses to “The Flash. The Rails one, not the Macromedia/Adobe one”

  1. RSL Says:

    Holy crap! I’ve been wondering why some code I’ve seen had those little hyphens at the end. [I knew about the equal sign at the start.] I must have missed that paragraph somewhere ’cause that’s the one thing I really hate about server-side coding: all the returns.

    I used to orchestrate this bizarre song and dance of server-side tags opening on one line, code on another, and closing on another still! This is going to make my code a heck of a lot leaner and meaner and certainly as formatted as I like it. Thanks a million!

  2. Erik Gregg Says:

    @flash[:message] if @flash[:message]
    @flash[:warning] if @flash[:warning]
    @flash[:error] if @flash[:error]

  3. Dave Lehman Says:

    key %>

    (from Ryan Bates’ Railscasts #18)

  4. Dave Lehman Says:

    (Hmm… it ate my code)

Leave a Reply

Spam is a pain, I am sorry to have to do this to you, but can you answer the question below?

Q: Type in the word 'ajax'