Forum: Ruby on Rails autocomplete using other models

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C1e5a9e9344b6d31b9df7303e6dc378a?d=identicon&s=25 Craig White (Guest)
on 2006-03-14 19:06
(Received via mailing list)
I've asked this in various ways but I can't seem to get much traction -
my guess is because not many people are doing this.

I am working in a controller/views called placements. Placements
belongs_to :client
I have a clients model/table - clients has_many :placements

in placements/find...this works fine...
<%= text_field_with_auto_complete :placement, :clwholename, {} %>

if I put the same code into placements/new or placements/edit, I get a
No method 'clwholename' error

The method is defined at the top of placements_controller.rb ...
  def auto_complete_for_placement_clwholename
    auto_complete_responder_for_clients params[:placement][:clwholename]
  end

I have taken the entire code from the view file placements/find.rhtml
and pasted it into placements/new and still get the same error.

The only difference of any significance I can figure out is that the
methods are slightly different...

def find
    @placements = Placement.find(:all)

whereas
def new
    @placement = Placement.new

and def edit
    @placement = Placement.find(params[:id])

but that wouldn't seem to be enough to break it would it?

I have spent various amounts of time the past few weeks playing with
this but it is rapidly coming to the point where it is holding me back.
Why would the auto_complete_for 'column from other model' work with a
find method but not edit/new methods?

Craig
858392acd1398aa6071fb1d44cc33842?d=identicon&s=25 John Smilanick (Guest)
on 2006-03-14 20:26
(Received via mailing list)
>
> if I put the same code into placements/new or placements/edit, I get a
> No method 'clwholename' error
I have not used text_field_with_auto_complete before, but I see it is
a wrapper for text_field. I would guess it means the same in both.
The error means the text_field is looking for an initial value and it
does this by calling @object.method (in your case:
@placement.clwholename). If the instance variable @placement is not
set to an object that has a method clwholename then you get this error.

> The only difference of any significance I can figure out is that the
>     @placement = Placement.find(params[:id])
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails

-John
--
John Smilanick
Computing Staff - Webmaster
Kavli Institute for Theoretical Physics
University of California, Santa Barbara
jsmilani@kitp.ucsb.edu
(805) 893-6307
C1e5a9e9344b6d31b9df7303e6dc378a?d=identicon&s=25 Craig White (Guest)
on 2006-03-14 20:41
(Received via mailing list)
On Tue, 2006-03-14 at 11:26 -0800, John Smilanick wrote:
> >
> > if I put the same code into placements/new or placements/edit, I get a
> > No method 'clwholename' error
> I have not used text_field_with_auto_complete before, but I see it is
> a wrapper for text_field. I would guess it means the same in both.
> The error means the text_field is looking for an initial value and it
> does this by calling @object.method (in your case:
> @placement.clwholename). If the instance variable @placement is not
> set to an object that has a method clwholename then you get this error.
----
hmmm...perhaps I've just been chasing the wrong dog all this time.

I will try to set it with an empty value within the method and see if it
makes happy method.

thanks

Craig
This topic is locked and can not be replied to.