# NEWBIE eruby basic form problem

**URL:** <https://www.ruby-forum.com/t/newbie-eruby-basic-form-problem/145610>\
**Category:** Ruby\
**Created:** [August 12, 2008, 2:20am UTC](https://www.ruby-forum.com/t/newbie-eruby-basic-form-problem/145610 "2008-08-12T02:20:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![woodzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f08c70/32.png) [@woodzer](https://www.ruby-forum.com/u/woodzer)\
**Post date:** [August 12, 2008, 2:20am UTC](https://www.ruby-forum.com/t/newbie-eruby-basic-form-problem/145610/1 "2008-08-12T02:20:19Z")

</div>

I’m trying to capture comments from a textarea field to add to a  
database but I cannot figure out how to deal with escaping the data.

 Your Comment:   
 Is there something I can do to "\<%=comment%\>" to handle '' "" etc.

Many thanks any help is appreciated

---

<div class="post-metadata">

**Author:** ![woodzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f08c70/32.png) [@woodzer](https://www.ruby-forum.com/u/woodzer)\
**Post date:** [August 12, 2008, 10:45am UTC](https://www.ruby-forum.com/t/newbie-eruby-basic-form-problem/145610/2 "2008-08-12T10:45:35Z")

</div>

Peter W. kirjoitti:

> Is there something I can do to “\<%=comment%\>” to handle ‘’ “” etc.
> 
> Many thanks any help is appreciated

You can escape characters in several different ways. The CGI class is  
handy here, too. Example follows:

require ‘cgi’  
puts CGI.escape(“black/white”)

You can also unescape strings, and so forth. See the docs at  
[http://ruby-doc.org/core/classes/CGI.html](http://ruby-doc.org/core/classes/CGI.html)

It there is some string in particular you are looking for, you can  
search for it with include?, and so on, using the String class, see docs  
here:  
[http://www.ruby-doc.org/core/classes/String.html](http://www.ruby-doc.org/core/classes/String.html)

Did you have a more specific problem in mind?

Casimir P.

---

<div class="post-metadata">

**Author:** ![woodzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f08c70/32.png) [@woodzer](https://www.ruby-forum.com/u/woodzer)\
**Post date:** [August 12, 2008, 2:28pm UTC](https://www.ruby-forum.com/t/newbie-eruby-basic-form-problem/145610/3 "2008-08-12T14:28:36Z")

</div>

Casimir wrote:

> Peter W. kirjoitti:
> 
> > Is there something I can do to “\<%=comment%\>” to handle ‘’ “” etc.
> > 
> > Many thanks any help is appreciated
> 
> You can escape characters in several different ways. The CGI class is  
> handy here, too. Example follows:
> 
> require ‘cgi’  
> puts CGI.escape(“black/white”)
> 
> You can also unescape strings, and so forth. See the docs at  
> [http://ruby-doc.org/core/classes/CGI.html](http://ruby-doc.org/core/classes/CGI.html)
> 
> It there is some string in particular you are looking for, you can  
> search for it with include?, and so on, using the String class, see docs  
> here:  
> [class String - RDoc Documentation](http://www.ruby-doc.org/core/classes/String.html)
> 
> Did you have a more specific problem in mind?
> 
> Casimir P.

Casimir  
Thanks for the tips. You gave me enough of a hint to to solve most of  
the problem. There still seems to be a problem with characters like %

Regards,  
Peter
