Hi guys, I''m trying to wrap my head around the rails autocompletion-functionality. I''m building a simple form for creating tasks, in which I would like to substitute a dropdown-list consisting of a collection of projects for an autocomplete-field. The completed project should be added with the task.project_id. Also, if task is submitted with a project that isn''t in the database, I would like a new project to be created and use the newly created project_id for the task. This is where I''m at now. The form in my view looks like this: <% form_remote_tag :url => { :action => ''newtask'' }, :update => ''task_list'' do %> <p> Task: <%= text_field ''task'', ''description'' %> Project: <%= text_field_with_auto_complete ''task'', ''project'' %> <%= submit_tag "New task!" %> </p> <% end %> and my controller looks like this: @newtask = Task.new @projects = Project.find(:all) @tasks = Task.find(:all) @task.project = @params[:project][:name] I''ve added the include javascript snippet in my layout and the "auto_complete_for :task, :project" in my . I know I''m missing both the _id-connection and the create a new project. I figure that it should probably be solved on a controller-level, but I don''t know where to start... Does anyone have any pointers on how I should progress from here? Any help is much appreciated! -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Xavier Noria
2007-Sep-25 10:04 UTC
Re: Autocomplete with _id (if query exists), else create new
On Sep 25, 2007, at 9:40 AM, Gus Vs wrote:> Hi guys, I''m trying to wrap my head around the rails > autocompletion-functionality. I''m building a simple form for creating > tasks, in which I would like to substitute a dropdown-list > consisting of > a collection of projects for an autocomplete-field. > > The completed project should be added with the task.project_id. > Also, if > task is submitted with a project that isn''t in the database, I would > like a new project to be created and use the newly created project_id > for the task.Have a look at model_auto_completer: http://agilewebdevelopment.com/plugins/model_auto_completer It maintains the project_id for you, and has an option :allow_free_text that allows the user to enter free text, in which case the project_id is set to the empty string. In the application a blank project_id means a project to be created. -- fxn Disclaimer: I am the author. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---