The Flash Responder

The scaffolded controller uses flash messages in both create and update actions. These messages are quite similar across different controllers. Wouldn’t it be nice if we could set these flash messages by default inside responders but still provide a nice API to change them?

Let’s implement this feature using the internationalization framework (I18n) so we can easily look up flash messages from YAML files, configure default values, and make it possible to translate such messages in the future. Let’s use rails plugin to create a new project called responders:

 
$ ​rails plugin new responders

Let’s start by writing some tests that access create, update, and destroy actions and ensure a flash message is being exhibited to ...

Get Crafting Rails 4 Applications, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.