473,407 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Alphabetic letter based search

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.
Mar 25 '09 #1
3 4242
improvcornartist
303 Expert 100+
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.
Mar 25 '09 #2
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...
Apr 3 '09 #3
improvcornartist
303 Expert 100+
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.
Apr 3 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Alan J. Flavell | last post by:
OK, today's email brought a comment from a reader, pointing out something that I'd long since noticed myself but hadn't done anything about it. On my pages, I've got a first-letter style on...
13
by: Ian Richardson | last post by:
At the moment I'm using a quicksort algorithm to sort a list of countries in alphabetic order. This worked wonderfully until someone came up with the Åland Islands... and this is at the end of the...
4
by: George Thompson | last post by:
How can I retrieve the first letter of data in a field within access? (using access 2k?) is this a VB thing or is there an obvious solution?
0
by: Tim::.. | last post by:
Hi... I'm having a big problem with a datagrid that obtains data from 2 different locations... Active Directory and SQL Database The data is inserted into a datatable and the sorted by a...
5
by: Xero | last post by:
How do you get a specific letter from a word? For example, in English, I would say: Get the fifth letter from the word "Computer" Then the letter 'u' will be returned. (C-O-M-P-U-..., 'u' is...
2
by: news | last post by:
We're trying to make a search form, and are wanting to create links for all the letters a person can click on and will bring up all entries that start with that letter. That part is easy: .......
3
by: PulkitZery | last post by:
Hi all, I need some help in my project (VB.NET) here is what I need: I need to convert Alphabetic number (a. b. c. d. …..) into the integers (for example a=1, b=2, c=3 and so on). Can anyone...
7
by: emre esirik(hacettepe computer science and enginee | last post by:
I used a structer in this program. typedef struct _guitar { int serial; :serial of item at the guitar store int price; :price of item at the guitar...
8
crystal2005
by: crystal2005 | last post by:
Hi guys, Just like the title, i'm looking for the example of C program that translates an alphabetic phone number into numeric. The idea as the following output Enter phone number:...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.