# How can I get HTML's varibles in embeded ruby?

**URL:** <https://www.ruby-forum.com/t/how-can-i-get-htmls-varibles-in-embeded-ruby/111300>\
**Category:** Ruby\
**Created:** [August 5, 2007, 9:38am UTC](https://www.ruby-forum.com/t/how-can-i-get-htmls-varibles-in-embeded-ruby/111300 "2007-08-05T09:38:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zhan\_feng\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a88e57/32.png) [@Zhan\_feng\_W](https://www.ruby-forum.com/u/Zhan_feng_W)\
**Post date:** [August 5, 2007, 9:38am UTC](https://www.ruby-forum.com/t/how-can-i-get-htmls-varibles-in-embeded-ruby/111300/1 "2007-08-05T09:38:57Z")

</div>

E.g.,I have following variables:  
myInput, DataFile,TagFile in the following segment HTML codes.

```
Select Asn1 File: 
    Select Asn1-bas File:
```

If in PHP, I can easily get them by $p\_DataFile, $p\_TagFile etc, How can  
I get the variables in embeded ruby?

Thanks

---

<div class="post-metadata">

**Author:** ![Zhan\_feng\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a88e57/32.png) [@Zhan\_feng\_W](https://www.ruby-forum.com/u/Zhan_feng_W)\
**Post date:** [August 5, 2007, 9:46am UTC](https://www.ruby-forum.com/t/how-can-i-get-htmls-varibles-in-embeded-ruby/111300/2 "2007-08-05T09:46:04Z")

</div>

Zhan feng Wang wrote:

> E.g.,I have following variables:  
> myInput, DataFile,TagFile in the following segment HTML codes.
> 
> ```
> Select Asn1 File: 
> Select Asn1-bas File:
> ```
> 
> If in PHP, I can easily get them by $p\_DataFile, $p\_TagFile etc, How can  
> I get the variables in embeded ruby?
> 
> Thanks

```
Select Asn1 File: 
     Select Asn1-bas File:
```

just a note, but i don’t think you want the ‘form’ action to go to the  
file itself (the rhtml) … it should go to the corresponding action that  
calls that template.

i believe what you are seeking for is params[:DataFile],  
params[:TagFile], etc.  
(this may be good for the ruby on rails forum, rather than this plain  
ruby forum) [http://www.ruby-forum.com/forum/3](http://www.ruby-forum.com/forum/3)

anyway hth.  
happy sunday

---

<div class="post-metadata">

**Author:** ![Zhan\_feng\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a88e57/32.png) [@Zhan\_feng\_W](https://www.ruby-forum.com/u/Zhan_feng_W)\
**Post date:** [August 5, 2007, 6:52pm UTC](https://www.ruby-forum.com/t/how-can-i-get-htmls-varibles-in-embeded-ruby/111300/3 "2007-08-05T18:52:22Z")

</div>

On Aug 5, 2007, at 2:46 AM, Shai R. wrote:

> > ```
> > <input type="reset" name="reset" value="Reset" OnClick="init()">
> > 
> > ```
> 
> ## just a note, but i don’t think you want the ‘form’ action to go to the happy sunday
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

OP didn’t say Rails. Could very well be serving some kind of eruby.

---

<div class="post-metadata">

**Author:** ![Zhan\_feng\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a88e57/32.png) [@Zhan\_feng\_W](https://www.ruby-forum.com/u/Zhan_feng_W)\
**Post date:** [August 5, 2007, 7:29pm UTC](https://www.ruby-forum.com/t/how-can-i-get-htmls-varibles-in-embeded-ruby/111300/4 "2007-08-05T19:29:24Z")

</div>

Zhan feng Wang wrote:

> ```
> </pre>
> 
> ```
> 
> If in PHP, I can easily get them by $p\_DataFile, $p\_TagFile etc, How can  
> I get the variables in embeded ruby?
> 
> Thanks

You probably want to use the CGI class:  
[http://ruby-doc.org/core/classes/CGI.html](http://ruby-doc.org/core/classes/CGI.html)

That page has plenty of tutorials on it, but the basics are:

require ‘cgi’  
cgi = CGI.new  
data\_file = cgi[‘DataFile’]

That’ll give you the value of the DataFile text field.

-Brett

---

<div class="post-metadata">

**Author:** ![Zhan\_feng\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a88e57/32.png) [@Zhan\_feng\_W](https://www.ruby-forum.com/u/Zhan_feng_W)\
**Post date:** [August 6, 2007, 2:58pm UTC](https://www.ruby-forum.com/t/how-can-i-get-htmls-varibles-in-embeded-ruby/111300/5 "2007-08-06T14:58:51Z")

</div>

Zhan feng Wang wrote:

> E.g.,I have following variables:  
> myInput, DataFile,TagFile in the following segment HTML codes.
> 
> If in PHP, I can easily get them by $p\_DataFile, $p\_TagFile etc, How can  
> I get the variables in embeded ruby?

Isn’t hpricot ([http://redhanded.hobix.com/inspect/hpricot01.html](http://redhanded.hobix.com/inspect/hpricot01.html)) an  
html parser package?

---

<div class="post-metadata">

**Author:** ![Zhan\_feng\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a88e57/32.png) [@Zhan\_feng\_W](https://www.ruby-forum.com/u/Zhan_feng_W)\
**Post date:** [August 6, 2007, 1:29am UTC](https://www.ruby-forum.com/t/how-can-i-get-htmls-varibles-in-embeded-ruby/111300/6 "2007-08-06T01:29:17Z")

</div>

Brett S. wrote:

> You probably want to use the CGI class:  
> [http://ruby-doc.org/core/classes/CGI.html](http://ruby-doc.org/core/classes/CGI.html)
> 
> That page has plenty of tutorials on it, but the basics are:
> 
> require ‘cgi’  
> cgi = CGI.new  
> data\_file = cgi[‘DataFile’]
> 
> That’ll give you the value of the DataFile text field.
> 
> -Brett

Thanks a lot.
