# Fetch data from text\_field

**URL:** <https://www.ruby-forum.com/t/fetch-data-from-text-field/131796>\
**Category:** Ruby\
**Created:** [March 13, 2008, 10:50am UTC](https://www.ruby-forum.com/t/fetch-data-from-text-field/131796 "2008-03-13T10:50:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![subhadip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3d9bf3/32.png) [@subhadip](https://www.ruby-forum.com/u/subhadip)\
**Post date:** [March 13, 2008, 10:50am UTC](https://www.ruby-forum.com/t/fetch-data-from-text-field/131796/1 "2008-03-13T10:50:05Z")

</div>

i am new in ruby.in my program i have one .rhtml file and two  
controller.  
1.in search.html.erb,the code is:  
\<% form\_tag(:action =\> ‘search’) do %\>  
Book\_Id:  
\<%= text\_field ‘book’, ‘book\_id’ %\>

\<%= submit\_tag “search” %\>  
\<% end %\>  
2.in controller  
class MainController \< ApplicationController  
def search

```
  @book=Book.find_by_book_id(params[:book_id])

 redirect_to :controller=>'search',:action=>'sv',:id=>@book

end

```

end

end  
3.in sv.html.erb  
\<% for book in @books %\>

```
<td><%=h book.book_id %></td>
<td><%=h book.book_name %></td>
</tr>

```

\<% end %\>  
4:in controller  
class SearchController \< ApplicationController  
def sv  
#@books=Book.find(:all)  
@books=Book.find(:all,:conditions =\> [“book\_id=@book.id”,  
params[:book\_id]])  
respond\_to do |format|  
format.html # index.html.erb  
format.xml { render :xml =\> @books }  
end  
end

end  
but i am unable to fetch data fron database corresponding to book\_id  
which i m given through textfield…  
any one can help me…
