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!! :-)
--
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
-~----------~----~----~----~------~----~------~--~---