I''ve implemented Ryan Bates''s Dynamic Select modules as done here: http://railscasts.com/episodes/88-dynamic-select-menus I have a Category select (hardware, software, media...) Based on the Category, I have a Product select (if hardware is chosen, then PC, Monitor, Printer...) That all works. But now I would like to show the product.description below the selected Product. HELP!??!?! Thanks for any input..... -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
soloriok-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2010-May-05 02:55 UTC
Re: Dynamic Selects - Dynamic View
Can you show the code in the corresponding views and controllers? On May 4, 2:30 pm, KT <mal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''ve implemented Ryan Bates''s Dynamic Select modules as done here:http://railscasts.com/episodes/88-dynamic-select-menus > > I have a Category select (hardware, software, media...) > Based on the Category, I have a Product select (if hardware is chosen, > then PC, Monitor, Printer...) > > That all works. > > But now I would like to show the product.description below the > selected Product. > > HELP!??!?! > > Thanks for any input..... > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Thanks and sure thing:
javascripts controller:
def dynamic_products
@products = Product.find(:all)
end
-------------------------------------------------------------------------------------------------------------
dynamic_products.js.erb:
var products = new Array();
<% for product in @products -%>
products.push(new Array(<%= product.category_id %>, ''<%=h
product.name %>'', <%= product.id %>));
<% end -%>
function categorySelected() {
category_id = $(''request_category_id'').getValue();
options = $(''request_product_id'').options;
options.length = 1;
products.each(function(product) {
if (product[0] == category_id) {
options[options.length] = new Option(product[1], product[2]);
}
});
if (options.length == 1) {
$(''product_field'').hide();
} else {
$(''product_field'').show();
}
}
document.observe(''dom:loaded'', function() {
categorySelected();
$(''request_category_id'').observe(''change'',
categorySelected);
});
--------------------------------------------------------------------------------------------------------------------------------
view:
<p>
<b><label for="request_category_id">Select
Category:<font
color="red">*</font></b></label><br>
<%= select( "request", "category_id", Category.find(
:all, :order =>
"name" ).collect { |c| [c.name, c.id] }, { :include_blank =>
true, :order => "name" })%>
</p>
<div>
<p id="product_field">
<b><label for="request_product_id">Select
Product/Service:<font
color="red">*</font></b><br></label>
<%= select( "request", "product_id", Product.find(
:all, :order =>
"name" ).collect { |p| [p.name, p.id] }, { :include_blank =>
true, :order => "name" })%>
-----------------------------------------------------------------------------------------------------------------------------------
On May 4, 7:55 pm, "solor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org"
<solor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Can you show the code in the corresponding views and controllers?
>
> On May 4, 2:30 pm, KT
<mal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
>
>
> > I''ve implemented Ryan Bates''s Dynamic Select modules
as done here:http://railscasts.com/episodes/88-dynamic-select-menus
>
> > I have a Category select (hardware, software, media...)
> > Based on the Category, I have a Product select (if hardware is chosen,
> > then PC, Monitor, Printer...)
>
> > That all works.
>
> > But now I would like to show the product.description below the
> > selected Product.
>
> > HELP!??!?!
>
> > Thanks for any input.....
>
> > --
> > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > For more options, visit this group
athttp://groups.google.com/group/rubyonrails-talk?hl=en.
>
> --
> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
> For more options, visit this group
athttp://groups.google.com/group/rubyonrails-talk?hl=en.
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Do I need to create another javascript to populate descriptions? I''m stuck... please help! On May 5, 7:49 am, KT <mal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks and sure thing: > > javascripts controller: > > def dynamic_products > @products = Product.find(:all) > end > > ------------------------------------------------------------------------------------------------------------- > dynamic_products.js.erb: > > var products = new Array(); > <% for product in @products -%> > products.push(new Array(<%= product.category_id %>, ''<%=h > product.name %>'', <%= product.id %>)); > <% end -%> > > function categorySelected() { > category_id = $(''request_category_id'').getValue(); > options = $(''request_product_id'').options; > options.length = 1; > products.each(function(product) { > if (product[0] == category_id) { > options[options.length] = new Option(product[1], product[2]); > } > }); > if (options.length == 1) { > $(''product_field'').hide(); > } else { > $(''product_field'').show(); > } > > } > > document.observe(''dom:loaded'', function() { > categorySelected(); > $(''request_category_id'').observe(''change'', categorySelected); > > }); > > -------------------------------------------------------------------------------------------------------------------------------- > view: > > <p> > <b><label for="request_category_id">Select Category:<font > color="red">*</font></b></label><br> > <%= select( "request", "category_id", Category.find( :all, :order => > "name" ).collect { |c| [c.name, c.id] }, { :include_blank => > true, :order => "name" })%> > </p> > > <div> > <p id="product_field"> > <b><label for="request_product_id">Select Product/Service:<font > color="red">*</font></b><br></label> > <%= select( "request", "product_id", Product.find( :all, :order => > "name" ).collect { |p| [p.name, p.id] }, { :include_blank => > true, :order => "name" })%> > > ----------------------------------------------------------------------------------------------------------------------------------- > On May 4, 7:55 pm, "solor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <solor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Can you show the code in the corresponding views and controllers? > > > On May 4, 2:30 pm, KT <mal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I''ve implemented Ryan Bates''s Dynamic Select modules as done here:http://railscasts.com/episodes/88-dynamic-select-menus > > > > I have a Category select (hardware, software, media...) > > > Based on the Category, I have a Product select (if hardware is chosen, > > > then PC, Monitor, Printer...) > > > > That all works. > > > > But now I would like to show the product.description below the > > > selected Product. > > > > HELP!??!?! > > > > Thanks for any input..... > > > > -- > > > 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-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.