auto_complete_for reimplementation.

0 views
Skip to first unread message

soulhunter

unread,
Oct 11, 2006, 10:24:18 PM10/11/06
to Ruby on Rails: Talk
Hi!

I would like to create a "custom" version of the "auto_complete_for"
function, I took the source code, and altered it to my needs, and, off
course, changed the name (from auto_complete_for to
custom_auto_complete_for , just for testing purporses). But rails keep
complaining that the new method doesn't exits!

I already did something similar with the "error_messages_for" function,
and just wrote the new one in the application_helper.rb file, and just
worked everywhere... but for the auto_complete_for function: I don't
know where to put it, I tried to put it in the helper, in the
controller itself, and even in the model: no, it doesn't work, like the
function didn't existed.

Any ideas?

Ildefonso Camargo

_Kevin

unread,
Oct 11, 2006, 11:09:11 PM10/11/06
to Ruby on Rails: Talk

If you want to override the standard 'auto_complete_for :action,
:method', all you have to do is define a method named
'auto_complete_for_action_method' in your controller and skip the
'auto_complete_for' line completely.

_Kevin

soulhunter

unread,
Oct 12, 2006, 7:58:02 AM10/12/06
to Ruby on Rails: Talk
Hi!

Thanks for your answer!

Yes, I know, I already did that, but the thing is: I want to replace
ALL the autocompletions in my project (more than 20), because I want to
change the search conditions (from LIKE to ~* , and need to add some
character substitution).

Thus, I tried to define this method (for testing purporses):

def custom_auto_complete_for(object, method, options = {})
define_method("auto_complete_for_#{object}_#{method}") do
find_options = {
:conditions => [ "#{method} ~* ? ", '%' +
params[object][method].downcase + '%'],
:order => "#{method} ASC",
:limit => 10 }.merge!(options)

@items = object.to_s.camelize.constantize.find(:all, find_options)

render :inline => "<%= auto_complete_result @items, '#{method}' %>"
end
end

That is my first approach, but when I try to call it, rails would just
say:

undefined method `custom_auto_complete_for' for
ContribuyentesController:Class

and the log says:

NoMethodError (undefined method `custom_auto_complete_for' for
ContribuyentesController:Class):

I defined the method in application_helper.rb , but I also tried to
define it locally in the "contribuyentes_controller.rb" file: I get the
same error.

Thanks in advance,

Ildefonso Camargo

soulhunter

unread,
Oct 13, 2006, 3:14:35 PM10/13/06
to Ruby on Rails: Talk
Hi, again.

I just found this:

http://www.sciwerks.com/blog/2006/09/25/multiple_auto_complete_plugin/

but I can't download the plug-in :( . Does anybody has it?, the server
just says:

script/plugin install
svn://sciwerks.com/home/sciwerks/public_svn/plugins/multiple_auto_complete
svn: Can't connect to host 'sciwerks.com': Connection refused

I would appreciate any help on this..... the plug-in clearly
reimplements the auto_complete_for method, wich is exactly what I need
to do.

Thanks in advance,

Ildefonso Camargo

On Oct 12, 7:58 am, "soulhunter" <ildefonso.cama...@gmail.com> wrote:
> Hi!
>
> Thanks for your answer!
>
> On Oct 11, 11:09 pm, "_Kevin" <kevin.olbr...@gmail.com> wrote:
>
>
>
> > On Oct 11, 10:24 pm, "soulhunter" <ildefonso.cama...@gmail.com> wrote:
>
> > > Hi!
>
> > > I would like to create a "custom" version of the "auto_complete_for"
> > > function, I took the source code, and altered it to my needs, and, off
> > > course, changed the name (fromauto_complete_forto
> > > custom_auto_complete_for , just for testing purporses). But rails keep
> > > complaining that the new method doesn't exits!
>
> > > I already did something similar with the "error_messages_for" function,
> > > and just wrote the new one in the application_helper.rb file, and just

> > > worked everywhere... but for theauto_complete_forfunction: I don't


> > > know where to put it, I tried to put it in the helper, in the
> > > controller itself, and even in the model: no, it doesn't work, like the
> > > function didn't existed.
>
> > > Any ideas?
>
> > > Ildefonso Camargo
> > If you want to override the standard 'auto_complete_for:action,
> > :method', all you have to do is define a method named
> > 'auto_complete_for_action_method' in your controller and skip the

> > 'auto_complete_for' line completely.Yes, I know, I already did that, but the thing is: I want to replace

_Kevin

unread,
Oct 13, 2006, 8:55:07 PM10/13/06
to Ruby on Rails: Talk
I'll check on it.

_Kevin

_Kevin

unread,
Oct 13, 2006, 10:42:17 PM10/13/06
to Ruby on Rails: Talk
Should be working now. If you still have trouble email me and I'll
send you a copy.

_Kevin

Reply all
Reply to author
Forward
0 new messages