Hello,
New Rails user, just joined up here. After doing a search, this thread seems like the closest thing I can find to the issue I'm having.
I'm using Rails 2.1.0 and I'm trying to get the auto_complete plugin to work. When I type something into the relevant text box, I don't get an error as such, but nor do I get any autocomplete suggestions.
I have downloaded/installed the plugin and I have also added the required <%= javascript_include_tag :defaults %> into my layout.
I have a RESTful MembersController with a new action that displays a form for a new member to use in order to sign up. Along with the MembersController, I have a Member model which has a belongs_to association with a Suburb model. This Suburb model stores the names and postcodes of suburbs. What I am wanting to achieve is to get an autocomplete field in the form displayed by the MembersController's new action that will allow a member to start typing their suburb and then the autocomplete is meant to kick in.
Looking in FireBug, I can see that when I type something into the text box, a GET request is being fired that is going to the auto_complete function and then immediately afterwards, another GET request is fired, going to my new action(?). But no suggestions appear. In both cases, the response I can see being returned in FireBug appears to be the whole new.html.erb, which doesn't seem right to me, but I don't know how to go about searching further into this issue.
I have been mainly trying to cobble together something from these two tutorials:
http://codeintensity.blogspot.com/2008/
ils-2.html (this one talks about drawing the autocomplete data from a different model, which is what I am trying to do)
http://trix.pl/blog/auto-complete-for-r
orial.html
Here is my code:
In routes.rb I have:
map.resources :members, :collection => {:auto_complete_for_member_suburb => :get }I made it a GET so that the forgery protection issue does not come into play as per one of the above tutorials.
In the new.html.erb for my MembersController, I have:
<%= text_field_with_auto_complete :member, :suburb, { :autocomplete => 'off' }, { :method => :get } %>In members_controller.rb, I have:
def auto_complete_for_member_suburb
re = Regexp.new("^#{params[:member][:suburb]}", "i")
find_options = { :order => "name ASC" }
@suburbs = Suburb.find(:all, find_options).collect(&:name).select { |s| s.match re }
render :inline => "<%= content_tag(:ul, @suburbs.map { |s| content_tag(:li, h(s)) }) %>"
end
I'm trying to implement a custom auto_complete_for_member_suburb as the data for the autocomplete is coming from another model (the Suburb model) in a similar way to what was described in one of the above tutorials.
Being new to Rails, I'm assuming the issue is just something stupid that I am overlooking... Possibly to do with the fact that I am trying to get the autocomplete to draw data from another model, which I understand is a little non-standard.
Sorry for the rather long first post. Any help at all would be greatly appreciated.
I would also love if anyone could recommend some good web pages or books on the subject of AJAX + Rails 2.1.0 as I am feeling a bit like a fish flopping around on the ground when it comes to using AJAX with Rails. 
Last edited by jonny_noog (2008-08-11 02:59:56)