Hi,
i need to implement a simple text function for the app i dev now.

1- the form in app/views/layouts

<% form_tag({:controller => "teachers", :action => "search"}, :method =>
"get") do %>
<%= text_field_tag :query, nil, :id => "search-text"  %>
<%= submit_tag("GO", :id => "search-submit") %>
<% end %>


2- the search method in teacher_controller.rb

  def search
    session[:query] = params[:query].strip if params[:query]

    if session[:query]
      @teachers = Teacher.find(:all, :conditions => ["materie LIKE ?",
"%#{session[:query]}%"], :order => "cognome ASC")
    end
end

3- the page for the result in app/view/teachers/search.html.erb

<h2 class="title">Teachers found</h2><br>
<% if searchresults.length == 0 %>
  <p>No teacher found...</p>
<% elsif params[:query] == "" %>
    <p>Insert a term, please.</p>
<% else %>
<ul>
<% for teacher in searchresults %>
    <li><%= link_to teacher.cognome , teacher_url(:id =>
teacher.id)%></li>
<% end %>
</ul>
<% end %>

But when I push the search button the page goes to the show function...

Heeeeeeelp !!!!

Many many thanks to all who...
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to