# Capturing textbox data in the same page

**URL:** <https://www.ruby-forum.com/t/capturing-textbox-data-in-the-same-page/131797>\
**Category:** Rails\
**Created:** [March 13, 2008, 11:23am UTC](https://www.ruby-forum.com/t/capturing-textbox-data-in-the-same-page/131797 "2008-03-13T11:23:14Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dibyendu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/838e76/32.png) [@dibyendu](https://www.ruby-forum.com/u/dibyendu)\
**Post date:** [March 13, 2008, 11:23am UTC](https://www.ruby-forum.com/t/capturing-textbox-data-in-the-same-page/131797/1 "2008-03-13T11:23:14Z")

</div>

Hi,

I am new to ruby.  
Can anyone help me with a simple code snippet where a user types in some  
date in any textbox and on submission, the same page opens with expects  
set of recorset in an HTML table. very urgent !

---

<div class="post-metadata">

**Author:** ![dibyendu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/838e76/32.png) [@dibyendu](https://www.ruby-forum.com/u/dibyendu)\
**Post date:** [March 13, 2008, 11:30am UTC](https://www.ruby-forum.com/t/capturing-textbox-data-in-the-same-page/131797/2 "2008-03-13T11:30:52Z")

</div>

I think this will help you

---

<div class="post-metadata">

**Author:** ![dibyendu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/838e76/32.png) [@dibyendu](https://www.ruby-forum.com/u/dibyendu)\
**Post date:** [March 13, 2008, 11:31am UTC](https://www.ruby-forum.com/t/capturing-textbox-data-in-the-same-page/131797/3 "2008-03-13T11:31:20Z")

</div>

Sijo Kg wrote:

> I think this will help you  
> [Ruby on Rails Screencasts - RailsCasts](http://railscasts.com/tags/11)

---

<div class="post-metadata">

**Author:** ![dibyendu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/838e76/32.png) [@dibyendu](https://www.ruby-forum.com/u/dibyendu)\
**Post date:** [March 13, 2008, 11:38am UTC](https://www.ruby-forum.com/t/capturing-textbox-data-in-the-same-page/131797/4 "2008-03-13T11:38:43Z")

</div>

Sijo Kg wrote:

> Sijo Kg wrote:
> 
> > I think this will help you  
> > [Ruby on Rails Screencasts - RailsCasts](http://railscasts.com/tags/11)

Hey thanx Sijo. But I need a simple example in ruby.  
I have a textbox, where I will fill date. And then on submission of  
that, the same page gets loaded passing the value of the textbox. And at  
last I need to fire some query to show relevant recordset in an HTML  
table format. Please help…

---

<div class="post-metadata">

**Author:** ![dibyendu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/838e76/32.png) [@dibyendu](https://www.ruby-forum.com/u/dibyendu)\
**Post date:** [March 13, 2008, 8:42pm UTC](https://www.ruby-forum.com/t/capturing-textbox-data-in-the-same-page/131797/5 "2008-03-13T20:42:45Z")

</div>

First things first. You need to buy a book. Go get “Agile Web  
Development With Rails”  
Second things: The suggestion to go watch a few rails casts is a good  
one. You should take Sijo’s Advice.  
Third things: here is a simple example, but You’ll need to adapt it to  
your situation. to do that you probably need to read your book.

## VIEW

\<% form\_tag do %\>  
\<%= date\_select :query\_date %\>  
\<% end %\>

\<% if @records %\>

 \<% for record in @records %\> \<% end %\> 

| Name |
| --- |
| \<%= record.name %\> |

\<% end %\>
## CONTROLLER

def view\_name  
if request.post?  
@records = ModelName.find(:all, :conditions =\> [“created\_on \> ?”,  
params[:query\_date]])  
end  
end

On Mar 13, 11:38 pm, Dibyendu Chatterjee \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![dibyendu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/838e76/32.png) [@dibyendu](https://www.ruby-forum.com/u/dibyendu)\
**Post date:** [March 14, 2008, 10:31am UTC](https://www.ruby-forum.com/t/capturing-textbox-data-in-the-same-page/131797/6 "2008-03-14T10:31:57Z")

</div>

On 14 Mar 2008, at 08:23, Dibyendu Chatterjee wrote:

> :order =\> [:day, :month, :year]
> 
> \<% form\_tag do %\>  
> \<%= date\_select :“aaqq”, :order =\> [:day, :month, :year] %\>

There’s 2 problems here. First of all, date\_select is one of those  
magic helpers where the first parameter is the name of an instance  
variable, and the second the name of a method. It makes things easy  
when what you are doing is editing a date property of an activerecord  
object.  
That’s not what you’re doing here though, so you should use select\_date.  
The second thing is that (either way) the date will get submitted as 3  
separate fields (one for year, one for month, one for day), and so it  
needs to be turned back into an actual date serverside. If you use  
date\_select and you assign the params to an activerecord object that  
will happen automatically, if you are using select\_date you have to do  
it yourself (use Date::civil or Time.mktime)

Fred

---

<div class="post-metadata">

**Author:** ![dibyendu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/838e76/32.png) [@dibyendu](https://www.ruby-forum.com/u/dibyendu)\
**Post date:** [March 14, 2008, 10:48pm UTC](https://www.ruby-forum.com/t/capturing-textbox-data-in-the-same-page/131797/7 "2008-03-14T22:48:10Z")

</div>

it might help to look at the file RAILS\_ROOT/logs/development.log

This file will tell you exactly what parameters are being submitted by  
your form and their values so you can construct your dates from there.  
Sorry about my example not working properly! haha

On Mar 14, 10:31 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![dibyendu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/838e76/32.png) [@dibyendu](https://www.ruby-forum.com/u/dibyendu)\
**Post date:** [March 14, 2008, 9:23am UTC](https://www.ruby-forum.com/t/capturing-textbox-data-in-the-same-page/131797/8 "2008-03-14T09:23:42Z")

</div>

It did work to a lot extent. But facing problem in :  
CONTROLLER :  
@records = ModelName.find(:all, :conditions =\> [“created\_on \> ?”,  
params[:query\_date]])

what has to be written in : query\_date.

I used :  
params[:aaqq] once and then tried with  
:order =\> [:day, :month, :year]

I failed in getting desired result… ☹ View C

FYI :::::

Here’s my view code :

\<% form\_tag do %\>  
\<%= date\_select :“aaqq”, :order =\> [:day, :month, :year] %\>  
  
\<%= submit\_tag( “Display Text!” ) %\>  
\<% end %\>

\<% if @records %\>

 \<% for record in @records %\> \<% end %\> 

| Name |
| --- |
| \<%= record.date %\> |

\<% end %\>

Here’s my controller code:

if request.post?  
@records = WdeColumnData.find(:all, :conditions =\> [“date \>  
params[:aaqq]”])  
end

---

<div class="post-metadata">

**Author:** ![dibyendu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/838e76/32.png) [@dibyendu](https://www.ruby-forum.com/u/dibyendu)\
**Post date:** [March 17, 2008, 1:45pm UTC](https://www.ruby-forum.com/t/capturing-textbox-data-in-the-same-page/131797/9 "2008-03-17T13:45:23Z")

</div>

Hey my code worked !! Thanx all.
