flash-like implementation

January 13, 2009 by pedro mota

Flash is a Ruby on Rails method to show (mainly warning/error) messages. Camping has no such method, so i implemented an approach for error messages. The thing is, after a post method in the controller, the redirect creates a new instance for the controller, loosing the class instance variables set before.\nSo, after talking a bit with Zimbatm at #camping, we setup what could be a good solution: to use the @state session variable.\n\n@state.error = ‘The unit is still operational, Dave. But it will fail within seventy-two hours’\n\nThe variable is cleared on the View layout method. Flash means just it. Show and clear. The layout code includes:\n\ndiv(:class => 'error') { p @state.error.to_s; @state.error = ''; } unless @state.error.blank?\n\nand the CSS .error class wraps the message inside a lightred box with a nice solid red border (say RoR?).

© 2018 | Follow on Twitter | pedro mg & Hugo