Link_to in the controller flash message?

How can one do something similar to:

redirect_to(:back, :notice => “Photo was successfully created. Click
here
to view it”)

The flash notice message is shown however, it shows: “Photo was
successfully created. Click here to
view it”. It displays the anchor element as a string instead of an
html element

Christian F. wrote in post #957990:

How can one do something similar to:

redirect_to(:back, :notice => “Photo was successfully created. Click
here
to view it”)

The flash notice message is shown however, it shows: “Photo was
successfully created. Click here to
view it”. It displays the anchor element as a string instead of an
html element

So don’t escape the HTML! Easy.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Try this

class YourController < ApplicationController
include ActionView::Helpers::SanitizeHelper

def your_action
redirect_to(:back, :notice => sanitize(“Photo was successfully
created. Click here to view it”))
end
end

If you haven’t used the sanitize method before, please read this
http://api.rubyonrails.org/classes/ActionView/Helpers/SanitizeHelper.html#method-i-sanitize

before using it.

Arailsdemo, I dont think the sanitize helper works in the controller
level. I get the error: undefined method `sanitize

Marnen, please be more specific!

Maybe the better idea is just to use some session variable instead of
flash? (just for cases like this one)

On Oct 29, 12:33pm, Christian F. [email protected]

On Nov 1, 11:50am, Christian F. [email protected]
wrote:

Arailsdemo, I dont think the sanitize helper works in the controller
level. I get the error: undefined method `sanitize

Marnen, please be more specific!

Look at where you’re displaying the contents of the flash; you may
need to either not call h() or use the raw helper to indicate that the
contents of the flash are safe to display

Fred

Did you include the module?

class YourController < ApplicationController
include ActionView::Helpers::SanitizeHelper

Christian F. wrote in post #958461:

Arailsdemo, I dont think the sanitize helper works in the controller
level. I get the error: undefined method `sanitize

Marnen, please be more specific!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs