Sha256: 20034421f217bf40aa5a34877faa0429bd7d9ee6045cc460f951e7161f02c8e8

Contents?: true

Size: 786 Bytes

Versions: 4

Compression:

Stored size: 786 Bytes

Contents

# Provides good default flash messages for controller actions.
# origin: RM
module BoringControllerTrait::FlashTrait
  as_trait do

    create.success.flash lambda { "#{translate_model_name(object)} created" }
    create.failure.flash lambda { error_flash("Could not save") }

    update.success.flash lambda { "#{translate_model_name(object)} updated" }
    update.failure.flash lambda { error_flash("Could not save") }

    destroy.success.flash lambda { "#{translate_model_name(object)} deleted" }
    destroy.failure.flash lambda { error_flash("Could not delete") }

    private

    # This is a hack because resource_controller uses flash[:notice] for everything
    def error_flash(msg)
      "<span class='error'>#{ERB::Util.html_escape msg}</span>".html_safe
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
serum-rails-0.2.1 spec/test_apps/rails-2-3/app/controllers/shared/boring_controller_trait/flash_trait.rb
serum-rails-0.2.0 spec/test_apps/rails-2-3/app/controllers/shared/boring_controller_trait/flash_trait.rb
serum-rails-0.1.1 spec/test_app/app/controllers/shared/boring_controller_trait/flash_trait.rb
serum-rails-0.1.0 spec/test_app/app/controllers/shared/boring_controller_trait/flash_trait.rb