this needs to be DRYed
my app is a "Getting Things Done" type.
so in my "inbox" view I can add it to a project and add context to it
using the ''take_action'' method.
in my ''inbox'' controller...
def take_action
@item = Item.find(params[:id])
end
# add project and context
def associate_project_context
@item = Item.find(params[:id])
@item.project =
Project.find_or_create_by_name(params[:item]["project_id"])
@item.context =
Context.find_or_create_by_name(params[:item]["context_id"])
if @item.update_attributes(params[:item])
flash[:notice] = ''Project was successfully associated to
item.''
redirect_to :action => ''list''
else
render :action => ''new''
end
end
def auto_complete_for_item_project_id
auto_complete_responder_for_projects params[:item][:project_id]
end
def auto_complete_for_item_context_id
auto_complete_responder_for_contexts params[:item][:context_id]
end
private
def auto_complete_responder_for_projects(value)
@projects = Project.find(:all,
:conditions => [ ''LOWER(name) LIKE ?'',
''%'' + value.downcase + ''%'' ],
:order => ''name ASC'')
render :partial => ''projects''
end
def auto_complete_responder_for_contexts(value)
@contexts = Context.find(:all,
:conditions => [ ''LOWER(name) LIKE ?'',
''%'' + value.downcase + ''%'' ],
:order => ''name ASC'')
render :partial => ''contexts''
end
--------------------------------------------------------------------------
view with form for the two auto complete boxes
<p><%= @item.name %></p>
<fieldset>
<legend>add a project and context</legend>
<%= start_form_tag :action =>
''associate_project_context'', :id => @item %>
project: <%= text_field_with_auto_complete :item, :project_id, {} %>
context: <%= text_field_with_auto_complete :item, :context_id, {} %>
<%= submit_tag ''add'' %>
<%= end_form_tag %>
</fieldset>
_context.rthml
<ul class="projects">
<% for context in @contexts do -%>
<li><%=h context.name %></li>
<% end -%>
</ul>
_projects.rhtml
<ul class="projects">
<% for project in @projects do -%>
<li><%=h project.name %></li>
<% end -%>
</ul>
--------------------------------------------------------------------------
maybe someone could suggest on DRYing it up?
On 3/22/07, moo <procoder.net-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> in a form if i have two autocomplete fields in which one depend on
> other..........
>
> like for ex...if we select country name...all the states should
> come ...both are autocomplete....
>
> please help me in this regards...
>
> moyeen.
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---