http://rpheath.com/posts/379-rails-plugin-for-pretty-flash-messages
Displaying flash messages is, for the most part, pretty consistent across all of my applications. I usually make use of three: notice, warning, and error. The notices are typically some shade of green, warnings are usually yellow-ish, and errors are always some form of red.
It’s tedious to keep doing the same “flash” stuff in every application. So I wrote a plugin that will hopefully take that pain away. It’s called pretty_flash, and can be found on GitHub. It’s really just for me, but generic enough to share.
Once setup, by default the three flash messages will look like:
Not too bad, but feel free to change it if you aren’t into pastels :-)
I’m not fond of setting flash messages via:
1 |
flash[:whatever] = "This is the whatever message." |
So I’ve added a couple of convenience methods to replace that. Now, in your controller you can set flash messages like this:
1 2 3 |
notice "This is a notice" warning "This is a warning" error "This is an error" |
And to display them to the world, somewhere in your view/layout, just call:
1 |
<%= display_flash_messages %> |
It will loop through all the messages set and display each one.
Since this plugin involves CSS and a few images, I’ve provided a rake task that will put those things in their proper places. You can simply copy what you need if you’re not lazy.
1 |
$ rake pretty_flash:install |
But!
You may want to check the assets/ folder in the plugin directory first, just to make sure you don’t have any files with the same name (the rake task will overwrite them if so).
Oh, and another thing. I always fade my flash messages after so long. I typically use either jQuery or Prototype to handle this, so I’ve added a flash.js file that covers both. If you so desire, just copy whichever snippet into your application.js file, and your flash messages will start fading after so many seconds.
Again, this plugin is really just for me, but I figured someone else might find it useful.
相关推荐
rails for zombies 课件
For a .NET developer, learning Rails is as much about the cultural and philosophical shifts in thinking as it is about the technical learning curve. In this book, we hope to break down some of these ...
Rails for Zombies. This is a tutorial of ruby on rails application.
Bootstrap 3 和 Rails 4(样例用的是Ruby 2.1.1,Rails 4.1.4) Table of Contents Preface 1 Chapter 1: Introducing Web Application Development in Rails 7 Why Bootstrap with Rails? 8 Setting up a Todo ...
Ruby for Rails 英文原版, pdf格式 <br>本书是一部专门为Rails实践而写的经典Ruby著作,由四部分组成,共17章。第一部分讲述Ruby和Rails的编程环境。第二部分和第三部分与 Rails紧密联系,着重对Ruby这门语言...
Rails debug plugin for netbeans ide 6.0. Zip format without subfix.
ruby on rails for eclipse开发插件
Ruby 的基本知识,...安装 ruby ,rails...mysql 数据库...用 rails 实现的是一个简单的网上书籍管理程序 ...
Pragmatic.Bookshelf.Rails.for.PHP.Developers
Rails for Java Developers
这是Agile Web Development with Rails for Rails 3.2, 为3.2的版本修改过的
适合初学者的ruby教程
[Pragmatic Bookshelf] Crafting Rails Applications Expert Practices for Everyday Rails Development (E-Book) ☆ 图书概要:☆ Rails 3 is a huge step forward. You can now easily extend the framework, ...
NULL 博文链接:https://qianjigui.iteye.com/blog/250876
Ruby On Rails For Dummies
weixin_rails_middleware, 微信集成 ruby weixin_rails_middleware for integration weixin.
从官网上下载的最新的rails4.0.3开发教材。不足之处是mobi版的,需要kindle阅读器,好在这个阅读器也是免费的。
Bootstrap for Rails is for Rails web developers who are struggling to get their website designs right. It will enable you to create beautiful responsive websites in minutes without writing much CSS ...
Packt.Publishing.Aptana.Radrails.An.Ide.for.Rails.Development.May.2008.pdf
Rails ::漂亮::记录器Pretty Logger是一个日志记录框架,可帮助您从页面检查日志,使用PrettyLogger.highlight方法可以轻松发现所需内容。如果要每小时进行一次日志轮换,请使用Pretty logger覆盖logger类,并保留...