From: Subhadip Chakraborty Date: 2008-03-13T18:50:06+09:00 Subject: fetch data from text_field 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 %> <%=h book.book_id %> <%=h book.book_name %> <% 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.. -- Posted via http://www.ruby-forum.com/.