In Rails, you can set flash [: error] when calling link_to?

For example, let's say I have the following:

link_to 'Page', page_path(foobar)

Is there a way to set flash [: error] in a link_to call that will display in page_path?

I am looking for something like:

link_to 'Page', page_path(foobar), :error => "Flash message"
+5
source share
2 answers

In your controller that responds to the link you have to do flash[:error] = message. It should be in the same place where you decide whether to redirect the administrator to the page edit. Once again he is in controller, not inview

+3
source

You must set flash [: error] in the controller, but you can use it if you want to send it by reference. Move the: error option to the route call:

link_to 'Page', page_path(foobar, :error => "Flash message")

- ,

flash [: error] = params [: error] || ", "

, URL-, URL- ()

"/pages/123?error=Flash%20message

- .

+1

All Articles