New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

rails_turbo_flash

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rails_turbo_flash

  • 0.1.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Rails Turbo Flash

Automatic flash message injection for Ruby on Rails Turbo Stream responses.

Installation

Add rails_turbo_flash to your Gemfile, or:

$ bundle add rails_turbo_flash

Getting Started

  1. Include the controller helper:

    class ApplicationController < ActionController::Base
      include RailsTurboFlash::Callbacks
    end
    
  2. Use the view helper to render a turbo stream target into your top-level layouts. For example, in app/views/layouts/application.html.erb:

    <%= turbo_flash_tag %>
    
    <%# Or with some additional attributes: %>
    
    <%= turbo_flash_tag class: 'fixed flex gap-8 justify-center top-0 right-0 z-50' %>
    
  3. Add flash messages in your controller actions with flash.now.

That's it!

Customizing

To customize Rails Turbo Flash, create a file config/initializers/rails_turbo_flash.rb.

The default values are shown below:

RailsTurboFlash.configure do |config|
  config.action = :prepend # The turbo stream action
end

To make Rails Turbo Flash look like your app, override the bundled views by adding them to your app. You can manually copy the specific views that you need to app/views/turbo_flash, or copy them to your application with the included generator:

$ rails generate rails_turbo_flash:views

See the bundled views.

Why and How

Unable to find an authoritative solution from the Turbo Rails team or Rails community for adding flash messages to turbo stream responses, I hacked this gem together. It aims to be DRY, simple, and unobtrusive. This solution was tailored specifically to my needs and works for me; I make no guarantees it's good for everyone.

Basically, it checks for a turbo_stream request format and appends a turbo stream to the response body via an after_action callback. The entire implementation is only a few lines of code.

Contributing

Here are a few ways you can help:

License

Open source under the terms of the MIT License.

FAQs

Package last updated on 13 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc