# bootstrap_flash_messages version 0.0.2 Robin Brouwer 45north Bootstrap alerts and Rails flash messages combined in one easy-to-use gem. ## Installation You can use this gem by putting the following inside your Gemfile: gem "bootstrap_flash_messages" Now you need flash.en.yml for the flash messages. rails g bootstrap_flash_messages:locale And that's it! ## Changes Version 0.0.2 changes (10/08/2012): - Changed the 'x' in close to & t i m e s ; Version 0.0.1 changes (08/08/2012): - Changed redirect_to method - Added flash! and flash_now! methods - Added flash_messages helper - Made a gem out of it ## Usage You need [Twitter Bootstrap](http://twitter.github.com/bootstrap) for the styling and close button. You can still use it without Bootstrap, but you need to style it yourself. This gem uses the [Bootstrap alerts](http://twitter.github.com/bootstrap/components.html#alerts). All flash messages are defined inside config/locales/flash.en.yml. They are nested like this: en: flash_messages: controller_name: action_name: success: "It worked!" info: "There's something you need to know..." warning: "You should watch out now." error: "Oh no! Something went wrong." You have four keys: :success :info :warning :error When you've defined the messages it's really easy to call them inside your Controller. class PostsController def create @post = Post.new(params[:post]) if @post.save redirect_to(@post, :flash => :success) else flash_now!(:error) render("new") end end end You can use the `:flash` parameter inside the `redirect_to` method (note: this gem changes the redirect_to method!) to set the flash messages. You only need to pass the corresponding key and the gem will automatically set `flash[:success]` to `t("flash_messages.posts.create.success")`. The `:flash` parameter also accepts an Array. redirect_to(@post, :flash => [:success, :info]) You can still use a Hash to use the default `redirect_to` behavior. When you don't want to use the `redirect_to` method to set the flash messages, you can use the `flash!` method. flash!(:success, :info) redirect_to(@post) When you need to use `flash.now` you can use the new `flash_now!` method. flash_now!(:error, :warning) You use `flash_now!` in combination with rendering a view instead of redirecting. Now's the time to show these messages to the user. Inside the layout (or any other view), add the following: