Rails plugin for pretty flash messages
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.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
jQuery 전후 예이 기사에서는 jquery after() 및 before() 메소드의 예를 볼 것입니다. before() 메서드는 선택한 요소 앞에 지정된 콘텐츠를 삽입합니다. after() 메서드는 선택한 요소 뒤에 지정된 콘텐츠...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.