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 知识点解析 #### 一、Rails for Zombies 介绍 Rails for Zombies 是一套面向初学者的 Ruby on Rails 教程。通过一系列有趣且互动性强的练习,帮助学习者掌握 Rails 的基本概念和技术。课程...
《Ruby on Rails for Dummies》是一本专门为初学者设计的Ruby on Rails教程,它旨在帮助新手快速理解并掌握这个强大的Web开发框架。Ruby on Rails(简称Rails)是基于Ruby编程语言构建的一个开源Web应用程序框架,它...
Rails for Zombies是一份面向初学者的教程,通过学习本教程,用户能够掌握创建Ruby on Rails应用程序的基本知识。 Rails for Zombies教程中的"Deep in the CRUD"部分深入讲解了CRUD(创建Create、读取Retrieve、...
**Ruby for Rails** Ruby是一种面向对象的动态编程语言,它以其简洁、优雅的语法和强大的元编程能力而闻名。在Web开发领域,Ruby与Rails框架的结合,即Ruby on Rails(RoR),开创了Web应用的新纪元。Ruby on Rails...
Ruby for Rails 英文原版, pdf格式 <br>本书是一部专门为Rails实践而写的经典Ruby著作,由四部分组成,共17章。第一部分讲述Ruby和Rails的编程环境。第二部分和第三部分与 Rails紧密联系,着重对Ruby这门语言...
Rails debug plugin for netbeans ide 6.0. Zip format without subfix.
标题 "Rails 集成Open Flash Charts" 涉及的是在Ruby on Rails框架中集成Open Flash Chart这一图表库的技术细节。Open Flash Chart是一个开源的Flash图表生成器,它允许开发者通过简单的API创建各种复杂的图表,包括...
"Rails Open Flash Chart" 是一个基于Ruby on Rails框架的库,用于在Web应用程序中生成交互式的Flash图表。这个库允许开发者轻松地创建各种统计图表,如折线图、柱状图、饼图等,以便更好地可视化数据。由于Flash在...
ruby on rails for eclipse开发插件
Pragmatic.Bookshelf.Rails.for.PHP.Developers
《Rails for Java Developers》是一本专为Java开发者撰写的书籍,旨在帮助他们快速掌握Ruby on Rails框架。本书由Stuart Halloway和Justin Etheredge合著,并于2007年2月出版。该书的目标读者是那些对Ruby on Rails...
### Agile Web Development with Rails for Rails 3.2 #### 核心知识点概览 - **Rails 3.2概述** - **敏捷开发方法论** - **Model-View-Controller (MVC) 模式** - **Ruby on Rails基础与高级特性** - **面向对象...
[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
Flash_messages_helper是一个方便的库,为Rails应用提供了一种灵活的方式来展示Flash消息。这个库简化了在视图层处理Flash消息的过程,使得代码更整洁,同时也提供了自定义配置的可能性。 首先,Flash消息在Rails中...
rails plugin install https://..../..git ``` 插件会被安装到`vendor/plugins`目录下,提供额外的功能或扩展。 以上就是Rails3的一些常用命令行操作。熟练掌握这些命令,将极大地提高你的开发效率,使你在构建...
从官网上下载的最新的rails4.0.3开发教材。不足之处是mobi版的,需要kindle阅读器,好在这个阅读器也是免费的。
### Ruby on Rails For Dummies #### 核心知识点解析 **1. Ruby on Rails 概述** - **定义与特点**:Ruby on Rails(简称 Rails 或 RoR)是一种基于 Ruby 语言的开源 Web 应用框架,它采用了 Model-View-...