Ask A Question

Notifications

You’re not receiving notifications from this thread.

Pass variable to Flash object

Denis Omerovic asked in General

I'm trying to pass a variable to flash messages object. I want to autohide flash messages(not each message) after 5 seconds in Stimulus controller. So I want to be able to set data-flash-autohide-value="true or false" in HTML.

One thing that I'm not sure how to pass this true or false from controller?

redirect_to some_path, notice: "Some message", autohide: true - this is clearly not working

so I can pass that variable in HTML stimulus value

Reply

Have any updates?

Reply

You can use html_safe on the notice message to allow them to include HTML.

redirect_to some_path, notice: "<div data-controller=\"autohide\">Some message</div>"
Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.