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 %>
Task: <%= text_field 'task', 'description' %> Project: <%= text_field_with_auto_complete 'task', 'project' %> <%= submit_tag "New task!" %>
<% 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!