How to allow custom flash keys in a redirect_to call in Rails 3

后端 未结 2 643
有刺的猬
有刺的猬 2020-12-31 06:11

In Rails 3, you can pass has attributes directly to redirect_to to set the flash. For example:

redirect_to root_path, :notice => \"Something          


        
2条回答
  •  旧巷少年郎
    2020-12-31 07:09

    In Rails 4 you can do this

    class ApplicationController < ActionController::Base
      add_flash_types :error, ...
    

    and then somewhere

    redirect_to root_path, error: 'Some error'
    

    http://blog.remarkablelabs.com/2012/12/register-your-own-flash-types-rails-4-countdown-to-2013

提交回复
热议问题