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 -%>
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 :)
August 16th, 2005 at 6:56 am
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!
June 12th, 2006 at 2:17 am
@flash[:message] if @flash[:message]
@flash[:warning] if @flash[:warning]
@flash[:error] if @flash[:error]
January 19th, 2009 at 6:19 am
(from Ryan Bates’ Railscasts #18)
January 19th, 2009 at 6:20 am
(Hmm… it ate my code)