# How to get information stored in a form by using ruby-rails

**URL:** <https://www.ruby-forum.com/t/how-to-get-information-stored-in-a-form-by-using-ruby-rails/47573>\
**Category:** Rails\
**Created:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/how-to-get-information-stored-in-a-form-by-using-ruby-rails/47573 "2005-11-12T12:49:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sayoyo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@sayoyo](https://www.ruby-forum.com/u/sayoyo)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/how-to-get-information-stored-in-a-form-by-using-ruby-rails/47573/1 "2005-11-12T12:49:30Z")

</div>

Hi,

I’m a newbie with ruby-rails (also with web  
developpement) I want to create a form to get data  
from the user, like text field and combobax, button,  
etc. I used “text\_field\_tag” or other “tag” to  
genenate those components on the html, but after that  
I have no idea how to get the data from the  
components, I read the examples and documentations  
about how to create the componenets, but I didn’t find  
anything which talk about how to extract them… Can  
someone please tell me how to do it or where can I  
find the documentation!!!

Thanks you very much!!!

sayoyo

* * *

Yahoo! FareChase: Search multiple travel sites in one click.  
[http://farechase.yahoo.com](http://farechase.yahoo.com)

---

<div class="post-metadata">

**Author:** ![sayoyo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@sayoyo](https://www.ruby-forum.com/u/sayoyo)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/how-to-get-information-stored-in-a-form-by-using-ruby-rails/47573/2 "2005-11-12T12:49:33Z")

</div>

On Nov 9, 2005, at 7:55 AM, Saiho Y. wrote:

> anything which talk about how to extract them… Can  
> someone please tell me how to do it or where can I  
> find the documentation!!!

Is there any particular reason you’re using ‘tag’ and  
‘text\_field\_tag’? It’s usually much simpler to use the form  
helpers. For example, in a view such as edit.rhtml:

\<%= text\_field ‘user’, ‘name’ %\>

and then in your controller you could access the user’s name via:

def edit  
@name = params[:user][:name]  
end

If you need further help, perhaps you can be more specific with your  
question or show examples of what you’ve already tried and why.

Duane J.  
(canadaduane)

---

<div class="post-metadata">

**Author:** ![sayoyo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@sayoyo](https://www.ruby-forum.com/u/sayoyo)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/how-to-get-information-stored-in-a-form-by-using-ruby-rails/47573/3 "2005-11-12T12:49:33Z")

</div>

Hi,

the reason I use “\_tag” is because I don’t have a  
model (no database) If I understand well the mecanism,  
the helpers without “tag”, they send information  
directly to the model…so that’s why I didn’t used  
them.

After a lot of tryings, I find out that I can get the  
info from the variable “@params”, like  
"@params[‘post’], but I don’t know if it is the  
correct way to get the information.

Thanks you very much

sayoyo

this is an example.

def buildTable  
if @params.include?(‘post’) then  
@checkTextField = @params[‘post’]  
else  
@checkTextField = nil  
end  
end

buildTable.rhtml

 Build Table \<%= start\_form\_tag :action =\> :buildTable %\>   

```
<%= text_field_tag(name = "post", nil, "size" =>

```

“20”, “maxsize”=\>“20”) %\>

```
<%= submit_tag(value = "run") %>
<%= submit_tag(value = "cancel") %><br>
<%= end_form_tag %>

<%= @checkTextField %>
<%= debug(@params) %>
</body>

```

— Duane J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > genenate those components on the html, but after  
> > Is there any particular reason you’re using ‘tag’  
> > def edit
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

* * *

Yahoo! FareChase: Search multiple travel sites in one click.  
[http://farechase.yahoo.com](http://farechase.yahoo.com)

---

<div class="post-metadata">

**Author:** ![sayoyo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@sayoyo](https://www.ruby-forum.com/u/sayoyo)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/how-to-get-information-stored-in-a-form-by-using-ruby-rails/47573/4 "2005-11-12T12:49:53Z")

</div>

On Nov 9, 2005, at 1:39 PM, Saiho Y. wrote:

> "@params[‘post’], but I don’t know if it is the  
> correct way to get the information.
> 
> Thanks you very much

No problem. Some comments about the code below…

> def buildTable  
> if @params.include?(‘post’) then  
> @checkTextField = @params[‘post’]  
> else  
> @checkTextField = nil  
> end  
> end

This method could be simplified, like this:  
def buildTable  
@checkTextField = params[:post]  
end

If there is no ‘post’ key in the params hash, then it will be nil by  
default so there’s no need to add the conditional statement.

> buildTable.rhtml
> 
> Build Table \<%= start\_form\_tag :action =\> :buildTable %\>

You may consider using the convention of underscores instead of  
camelCase, e.g.: start\_form\_tag :action =\> build\_table. It’s a Ruby  
convention that Rails sometimes relies on for conversion between  
camelCase and underscored variables.

> \<%= text\_field\_tag(name = “post”, nil, “size” =\>  
> “20”, “maxsize”=\>“20”) %\>
> 
> \<%= submit\_tag(value = “run”) %\>  
> \<%= submit\_tag(value = “cancel”) %\>

The above two lines look a little odd to me… you’re assigning the  
variable called ‘value’ twice, but then not using it below. Perhaps  
you meant to use a symbol-as-key hash like this:

submit\_tag(:value =\> “run”)  
submit\_tag(:value =\> “cancel”)

Good luck!  
Duane J.  
(canadaduane)
