Juan Moreno wrote:
> Hello!!!
> 
>     first of all sorry for my English! :-(
> 
>    Well I'm trying to make an auto_complete in my application, but it's
> getting hard to do it. This is all what I've done:
> 
> 1.I'm working with rails 2.1 and Postgres
> 2.My model name is: Alumno
> 3.My record name is: nombre in Alumno tables
> 4.I install the pluging with this command
> (http://wiki.rubyonrails.org/rails/pages/How+to+use+text_field_with_auto_complete):
> 
>    script/plugin install auto_complete
> 
> 5.in my view (example.rhtml)
> <html xmlns="http://www.w3.org/1999/xhtml";>
> <head>
>     <meta http-equiv="content-type" content="text/html; charset=utf-8"
> />
>     <title>Mi boleta en la WEB</title>
>     <%= javascript_include_tag :defaults %>
>     <%= javascript_include_tag 'prototype' %>
>     <%= javascript_include_tag "scriptaculous/prototype" %>
>     <%= javascript_include_tag "scriptaculous/scriptaculous" %>
>     <%= javascript_include_tag 'scriptaculous' %>
> 
>     <%= stylesheet_link_tag "example" %>
>     <%= javascript_include_tag :all, :cache => true %>
> 
> </head>
>     <body>
> 
> <%= text_field_with_auto_complete :alumno, :nombre, { :size => 15 },
> :skip_style => true -%>
> 
>    </body>
>  </html>
> 
> 6. my model (alumno.rb)
> ActiveRecord::Base.establish_connection(
>         :adapter => 'postgresql',
>         :host    => 'localhost',
>         :port    => "5432",
>         :username=> 'XXXXX',
>         :password=> 'XXXXXX',
>         :database=> 'boletin'
>         );
> 
> 
> class Alumno < ActiveRecord::Base
> 
> end
> 
> 7.my controller(completar_controller.rb)
> class CompletarController < ApplicationController
>  auto_complete_for :alumno, :nombre, :limit => 15
>   def index
> 
>        @alumno = Alumno.new
>        render :action => 'example'
>     end
> 
>   def auto_complete_for_alumno_nombre
>      search = params[:alumno][:nombre]
>      @nombres = Alumno.find(search) unless search.blank?
>      render :partial => "result"
>   end
> 
> end
> 
> 8.my partial (_result.rhtml)
> <ul class="autocomplete_list">
>   <% for nombre in @nombres .to_a -%>
>     <li class="autocomplete_item"><%= nombre.nombre %>
> 
> <% end -%>
> 
> 9.my CSS (complete.css)
> 
> .auto_complete {
>       position:absolute;
>       width:250px;
>       background-color:white;
>       border:1px solid #888;
>       margin:0px;
>       padding:0px;
> }
> 
> .auto_complete ul {
>       list-style-type: none;
>       margin:0px;
>       padding:0px;
> }
> 
> .auto_complete ul li.selected
> {
>       background-color: #bbf;
> 
> }
> 
> .auto_complete ul li {
>       list-style-type: none;
>       display:block;
>       margin:0;
>       padding:2px;
>       height:16px;
> }
> 
> That's all I have. The problem is that, it doesn't do anything, I can't
> see anything in my  text_field_with_auto_complete, it doesn't show any
> error, can someone help me please I really want to get it right..thank
> you!! :-)

Hi Juan.

As I'm fairly new to RoR I may not be the right one to solve your 
problem. But since you ask so direct here is what I did:

I got inspired by (more or less copied) this example:
http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/65f6f9011fa78b41/d45c3f04c2eacf4a?lnk=gst&q=text_field_with_auto_complete#d45c3f04c2eacf4a

Especially this part about the "auto_complete" method:
def auto_complete_for_person_name
  @people = Person.find(:all,
    :conditions => ["name LIKE ? AND org = ?", "#{params[:person]
[:name]}%",  params[:person][:org]],
    :order => "name ASC")
  unless @people.blank?
    render :inline => "<%= content_tag(:ul,
      @people.map{|person|
        content_tag(:li, h(person)) }) %>"
  else
    render :inline => ""
  end
end

Remember I'm using Rails ver 1.2.6 - so it may not work for your 
version.

Good Luck!

Peter
-- 
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