Rails auto complete with form_for and fields_for support
I’ve forked the Rails auto_complete plugin to add support for the following usage:
Ruby
-
<% form_for(@foo) do |f| %>
-
<%= f.text_field_with_auto_complete :bar %>
-
<% end %>
This fork also supports nested fields_for calls:
Ruby
-
<% form_for(@foo) do |f| %>
-
<% f.fields_for(@foo.baz) do |baz_f| %>
-
<%= baz_f.text_field_with_auto_complete :quux %>
-
<% end %>
-
<% end %>
You can find my fork on Github, here.
January 31st, 2009 at 4:42 am
Hi Warren,
I just noticed this week that we both forked the auto_complete plugin recently to do this; you can read about my take on it here:
http://patshaughnessy.net/repeated_auto_complete
This seems like an obvious missing feature or bug with auto_complete; have you tried submitting a patch to the original rails/auto_complete version?
January 31st, 2009 at 4:52 pm
Wow. I love the internet. Two solutions to my problem. Unfortunately neither worked. Yours came the closest. Primarily because your api matches up with the way Rails does things better.
The problem yours has is in auto_complete_macros_helper.rb when auto_index is null (when there isn’t a value) it calls tag_id which doesn’t match the id being generated. I removed that last if statement in #tag_id_for and everything worked like a champ.
Mine is working but more than likely I am doing it wrong, so could you publish some example code using the plugin?
Thanks!!
January 31st, 2009 at 5:02 pm
Pat,
I haven’t had a chance to really work it out and see if there are any further bugs.
Carl,
Like this one. Thanks for the heads up, I’d not come across that in my limited testing (ie it works for me).
I’ll take a look and post an update soon.
January 9th, 2010 at 11:31 pm
I am having strange problems about routing. I already have an auto_complete field that works, but adding a new one will make Rails fail to recognize the route. Any idea?