Connecting Tech Pros Worldwide Help | Site Map

Alphabetic letter based search

  #1  
Old March 25th, 2009, 10:02 AM
Newbie
 
Join Date: Dec 2007
Posts: 10
Hi,

i have list of alphabets from A to Z .if i click on any one letter that should give me all the name starting with that corresponding letter from the database and should be displayed in the same page.

if i use each letter as a link(link_to) i cant display them in the same page.

if i use link_to_remote i am not able to get the params value of the letter i.e...Which letter i clicked.. if anyone know about this plz give me a solution.
  #2  
Old March 25th, 2009, 03:09 PM
Expert
 
Join Date: May 2007
Posts: 213

re: Alphabetic letter based search


You could try Rails AJAX support to send the database results to a div within the same page. Or you could try using a partial.
  #3  
Old April 3rd, 2009, 06:35 AM
Newbie
 
Join Date: Dec 2007
Posts: 10

re: Alphabetic letter based search


Expand|Select|Wrap|Line Numbers
  1. <%= javascript_include_tag "prototype" %>
  2. <div class="element_links">
  3. <% for char in 'A'..'Z' %>
  4. <%= link_to_remote( "#{char}",
  5.                          :update => "content",
  6.                          :char => char,
  7.                          :url =>{:action => :alp_search }) %> </li>
  8.                          <% end %> 
  9.                          <div id="content"></div>
  10.                     <p>
  11. <ul>
This is my rhtml

and my controller is

Expand|Select|Wrap|Line Numbers
  1. def live_search
  2.      puts 'live_search'
  3.            @classifieds = Course.find(:all,:conditions => ["lower(course_name)like ?","%" + params[:search].downcase+ "%"])
  4.            puts @classifieds
  5.            if params['search'].to_s.size < 1
  6.            render :nothing => true
  7.            else
  8.                 if @classifieds.size > 0
  9.                    render :partial => 'display', :collection => @classifieds
  10.                    else
  11.                    render :text => "<li>No results found</li>", :layout => false
  12.                    end
  13.                 end
  14.               end

So as per the code if i click 'A' i should get all the courses which starts from 'A' from the database but am not able to get the params value of search.

In the place of link_to_remote if i use link i can get the correct result in the other page..but i want to display result in the same page..
is there is any way to do this...

Last edited by eWish; April 28th, 2009 at 01:56 PM. Reason: Added code tags
  #4  
Old April 3rd, 2009, 03:34 PM
Expert
 
Join Date: May 2007
Posts: 213

re: Alphabetic letter based search


Try adding content to your content div, such as
Expand|Select|Wrap|Line Numbers
  1. <div id="content">
  2.   <%= @content %>
  3. </div>
  4.  
Then, in your controller, set the content variable with the partial, like
Expand|Select|Wrap|Line Numbers
  1. def live_search
  2.   #...code...
  3.   @content = render_to_string(:partial => 'display', :collection => @classifieds)
  4.  
  5.   render :update do |page|
  6.     page.replace_html 'content', @content
  7.   end
  8. end
This should then update the div with your partial using your data collection.
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use of Soundex fields in access vonclausowitz@gmail.com answers 32 August 2nd, 2006 01:25 AM