Browse the Ruby on Rails Community.

You are here: Forums Ask a Rails expert Sanitizing html...

Replytotopic

Sanitizing html

Posted in Forums : Ask a Rails expert

 
Profile

Authority 12
Posting Rating 55
Sign in to rate this post

In my ‘view’ I have the following code:

<= post.description>

Both title and description have the following data in the database:

<EM>Jaane Tu…</EM> got a superstar opening

If I use sanitize_helper <= sanitize post.description> the lt or gt is converted to < or >, but nothing more.

What I am looking for is not having the tags displayed, but I want “Jaane Tu..” displayed in italics.

What am I doing wrong? Or is my expectation from the sanitize_helper not right?

 
Ernie

Authority 25
Posting Rating 99
Sign in to rate this post

Unless I’m missing something here, you shouldn’t be using any kind of sanitize if you want the HTML tags to make it through unchanged. In fact, escaping HTML tags is done by the “h” helper method—unless you’re calling that, the text should be inserted in the same format it existed in the description attribute.

 
Profile

Authority 12
Posting Rating 55
Sign in to rate this post

hi Ernie

Some html tags make it through. If I use “h” helper, all the tags like show the way they are rather than displaying the enclosed text in italics. Same result if I don’t use “h” as well.
I have sanitize_helper in action_view helpers folder (as part of actionpack gem). Still no luck.

 
Profile

Authority 12
Posting Rating 55
Sign in to rate this post

Using sanitized helper, tried removing tags by adding following line to environment.rb

config.action_view.sanitized_bad_tags = “em”, “object”, “embed”

The tags still show. Kindly note that this is how description is saved in the database (with <EM>Jaane Tu…</EM>)

 
Ernie

Authority 25
Posting Rating 99
Sign in to rate this post

Odd. It should work fine without the “h,” nor any special sanitization.

Replytotopic

Other Recent Topics

Ask a Rails expert : Routing problem using patterns for id

Ask a Rails expert : How to work with ror 2.1.1 using Netbeans IDE 6.1

Ask a Rails expert : json gem error

Ask a Rails expert : Problem with break

Ask a Rails expert : activesupport string first method error

Ask a Rails expert : url_for broken ?

Ask a Rails expert : map.routes.rb pls help

Ask a Rails expert : how to h tag in controller

Ask a Rails expert : Problem with Restful routing and partial form

Ask a Rails expert : will_paginate, search and ajax

Formatting Help
  • *bold*       _italics_      
    bq. (quotes)
  • "DSC":http://www.dsc.net
  • * or # (lists)
or cancel