# User input - spit code to browser

**URL:** <https://www.ruby-forum.com/t/user-input-spit-code-to-browser/137080>\
**Category:** Rails\
**Created:** [May 8, 2008, 8:00pm UTC](https://www.ruby-forum.com/t/user-input-spit-code-to-browser/137080 "2008-05-08T20:00:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9fc29f/32.png) [@jrun](https://www.ruby-forum.com/u/jrun)\
**Post date:** [May 8, 2008, 8:00pm UTC](https://www.ruby-forum.com/t/user-input-spit-code-to-browser/137080/1 "2008-05-08T20:00:45Z")

</div>

Hi, I am having trouble figuring out how to do this…

I am developing a new ruby on rails project and  
I am trying figure out how to write code so that when a user inputs  
their info into a form and they click on submit (or in my case, “get  
code”)  
the code generated will show in the browser so that they can copy and  
paste that code into their own html doc.

is there a way to do this with ruby? If so, I would greatly appreciate  
any  
help on this 🙂

thanks in advance!

Jeremy

---

<div class="post-metadata">

**Author:** ![jrun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9fc29f/32.png) [@jrun](https://www.ruby-forum.com/u/jrun)\
**Post date:** [May 8, 2008, 8:05pm UTC](https://www.ruby-forum.com/t/user-input-spit-code-to-browser/137080/2 "2008-05-08T20:05:22Z")

</div>

On Thu, May 8, 2008 at 11:00 AM, Jeremy Jeremy  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am developing a new ruby on rails project and  
> I am trying figure out how to write code so that when a user inputs  
> their info into a form and they click on submit (or in my case, “get  
> code”)  
> the code generated will show in the browser so that they can copy and  
> paste that code into their own html doc.

Whatever you put in the view will be shown in the browser. Perhaps  
you can clarify how your situation is different than normal?

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![jrun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9fc29f/32.png) [@jrun](https://www.ruby-forum.com/u/jrun)\
**Post date:** [May 8, 2008, 8:12pm UTC](https://www.ruby-forum.com/t/user-input-spit-code-to-browser/137080/3 "2008-05-08T20:12:58Z")

</div>

Hassan S. wrote:

> On Thu, May 8, 2008 at 11:00 AM, Jeremy Jeremy  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > I am developing a new ruby on rails project and  
> > I am trying figure out how to write code so that when a user inputs  
> > their info into a form and they click on submit (or in my case, “get  
> > code”)  
> > the code generated will show in the browser so that they can copy and  
> > paste that code into their own html doc.
> 
> Whatever you put in the view will be shown in the browser. Perhaps  
> you can clarify how your situation is different than normal?
> 
> –  
> Hassan S. ------------------------ removed\_email\_address@domain.invalid

Hi there, I apologize.

What i mean is… you have a basic page with a form on it. the user  
inputs the info into the form. Then when they click on the submit  
button… it produces the information into code viewable for the user to  
see.

an example is if i had a page where a user could enter a size, width and  
upload a picture into the form that is available on that page… then  
they hit the submit button. it would generate the code in the browser to  
tell the user what code they would need to put it on their own html doc.  
much like this code…  
so they enter their information into the form… they hit the submit  
button and this is what is produced on their browser window.  
 ![](http://www.rubyforum.com)

I hope that clears things a little 🙂

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![jrun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9fc29f/32.png) [@jrun](https://www.ruby-forum.com/u/jrun)\
**Post date:** [May 8, 2008, 8:30pm UTC](https://www.ruby-forum.com/t/user-input-spit-code-to-browser/137080/4 "2008-05-08T20:30:43Z")

</div>

i want it to act ALOT like this form at the bottom of the page

[http://www.mozilla.org/docs/web-developer/css1technote/css1tojs.html](http://www.mozilla.org/docs/web-developer/css1technote/css1tojs.html)

---

<div class="post-metadata">

**Author:** ![jrun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9fc29f/32.png) [@jrun](https://www.ruby-forum.com/u/jrun)\
**Post date:** [May 8, 2008, 8:31pm UTC](https://www.ruby-forum.com/t/user-input-spit-code-to-browser/137080/5 "2008-05-08T20:31:23Z")

</div>

On Thu, May 8, 2008 at 11:12 AM, Jeremy B.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> an example is if i had a page where a user could enter a size, width and  
> upload a picture into the form that is available on that page… then  
> they hit the submit button. it would generate the code in the browser to  
> tell the user what code they would need to put it on their own html doc.  
> much like this code…

So you’re not talking about code, you’re talking about markup.  
There /is/ a difference 🙂

> … and this is what is produced on their browser window.  
> ![](http://www.rubyforum.com)

require ‘cgi’  
example = ‘ ![](http://www.rubyforum.com)’  
CGI.escapeHTML(example)

is probably what you’re looking for. There are probably alternatives,  
but  
I’m new to RoR too 🙂

## HTH,

Hassan S. ------------------------ removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![jrun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9fc29f/32.png) [@jrun](https://www.ruby-forum.com/u/jrun)\
**Post date:** [May 8, 2008, 8:36pm UTC](https://www.ruby-forum.com/t/user-input-spit-code-to-browser/137080/6 "2008-05-08T20:36:28Z")

</div>

> So you’re not talking about code, you’re talking about markup.  
> There /is/ a difference 🙂
> 
> > … and this is what is produced on their browser window.  
> > ![](http://www.rubyforum.com)
> 
> require ‘cgi’  
> example = ‘ ![](http://www.rubyforum.com)’  
> CGI.escapeHTML(example)
> 
> is probably what you’re looking for. There are probably alternatives,  
> but  
> I’m new to RoR too 🙂
> 
> ## HTH,
> 
> Hassan S. ------------------------ removed\_email\_address@domain.invalid

Oh yeah, duh…lol i guess i should have said markup… sorry bout that

Okay I will try that 🙂 thanks very much for your help!
