curlysue282002-/E1597aS9LQAvxtiuMwx3w@public.gmane.org
2008-Nov-18 03:47 UTC
Creating a Query and then a select box based off query results
Hello, I am a newbie here and was hoping someone had some experience and suggestions on how to accomplish the below task: I would like to figure out how to give my users a prepopulated list based off there selection. I am creating am application that users specific servers and would like to show them the list of suppliers who build these servers. For example, if they chose a server X200 the next box would then prepopulate its self with the supplier thats is responsible for building this server. Anyone have any idea how I would go about doing this. I have a query that pulls the data but I have no idea what my next steps should be. Thank You, --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thorsten Müller
2008-Nov-18 11:22 UTC
Re: Creating a Query and then a select box based off query results
Roughly you will change the view when the user selects a server. Use the onchange (not onclick) event of the select box to trigger the next view. Obviously that should be an Ajax call, since there is no need to update the whole page. something similar, a category select with subcategories: the view with the main category select: <select name="category_main" id="category_main" style="float:left; width:200px;" onchange="<%= remote_function(:url => sub_category_depot_product_url(@product), :with => "''category_id='' + this.value") %>"> <option value=''666''>Kies een categorie</option> <%= options_from_collection_for_select(@categories, "id", "title", (@product.category ? @product.category.category_id : 0)) %> </select> the action to get the sub categories: def sub_category @product = Product.find(params[:id]) @categories = Category.find(:all, :order => "title ASC", :conditions => "category_id = #{params[:category_id]} AND published=1") respond_to do |format| format.js end end the ajax response used by this action: page.replace(:category_sub, :partial => ''depot/products/ sub_category_select'', :locals => {:categories => @categories, :product => @product}) and the partial used by the ajax response: <select name="product[category_id]" id="category_sub" style="float:left; width:200px; margin-left:8px;"> <%= options_from_collection_for_select(categories, "id", "title", product.category_id) %> </select> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Christie Clark
2008-Nov-18 19:33 UTC
Re: Creating a Query and then a select box based off query results
Thanks, this pretty helpful. I am going through this step by step. Had no idea even how to begin this or even what to call it when try to find a solution --- On Tue, 11/18/08, Thorsten Müller <thorsten-1oxKqHKwyltBDgjK7y7TUQ@public.gmane.org> wrote: From: Thorsten Müller <thorsten-1oxKqHKwyltBDgjK7y7TUQ@public.gmane.org> Subject: [Rails] Re: Creating a Query and then a select box based off query results To: "Ruby on Rails: Talk" <rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> Date: Tuesday, November 18, 2008, 6:22 AM Roughly you will change the view when the user selects a server. Use the onchange (not onclick) event of the select box to trigger the next view. Obviously that should be an Ajax call, since there is no need to update the whole page. something similar, a category select with subcategories: the view with the main category select: <select name="category_main" id="category_main" style="float:left; width:200px;" onchange="<%= remote_function(:url => sub_category_depot_product_url(@product), :with => "''category_id='' + this.value") %>"> <option value=''666''>Kies een categorie</option> <%= options_from_collection_for_select(@categories, "id", "title", (@product.category ? @product.category.category_id : 0)) %> </select> the action to get the sub categories: def sub_category @product = Product.find(params[:id]) @categories = Category.find(:all, :order => "title ASC", :conditions => "category_id = #{params[:category_id]} AND published=1") respond_to do |format| format.js end end the ajax response used by this action: page.replace(:category_sub, :partial => ''depot/products/ sub_category_select'', :locals => {:categories => @categories, :product => @product}) and the partial used by the ajax response: <select name="product[category_id]" id="category_sub" style="float:left; width:200px; margin-left:8px;"> <%= options_from_collection_for_select(categories, "id", "title", product.category_id) %> </select> --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---