Hi all,
I''m trying to create a related dropdown box:
In my view:
<select name="category" id="category">
<option value="">Select category</option>
<% @categories.each do |category| %>
<option value="<%= category.id %>">
<%= category.title %>
</option>
<% end %>
</select>
<select id=''brand_id_container''
name=''brand_id_container''>
<option value=''''>No Brand</option>
<% for brand in @brands -%>
<option value=''<%= brand.id %>''><%=
brand.title %></option>
<% end -%>
</select>
<%= observe_field("category",
:frequency => 0.25,
:update => "brand_id_container",
:url => { :action => :get_brands_for_category },
:with => "''category_id=''+value") %>
In my controller:
def get_brands_for_category
@brands = Brand.find_all_by_category_id(@params["category_id"])
end
Somehow it does not work. The related dropdown list does not change
contents. Does anybody have an idea why?
Regards,
Harm de Laat
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060113/d339337b/attachment.html
Anybody? On 1/13/06, Harm de Laat <harmdelaat@gmail.com> wrote:> > Hi all, > > I''m trying to create a related dropdown box: > > In my view: > > <select name="category" id="category"> > <option value="">Select category</option> > <% @categories.each do |category| %> > <option value="<%= category.id %>"> > <%= category.title %> > </option> > <% end %> > </select> > > <select id=''brand_id_container'' name=''brand_id_container''> > <option value=''''>No Brand</option> > <% for brand in @brands -%> > <option value=''<%= brand.id %>''><%= brand.title %></option> > <% end -%> > </select> > > <%= observe_field("category", > :frequency => 0.25, > :update => "brand_id_container", > :url => { :action => :get_brands_for_category }, > :with => "''category_id=''+value") %> > > In my controller: > > def get_brands_for_category > @brands = Brand.find_all_by_category_id (@params["category_id"]) > end > > Somehow it does not work. The related dropdown list does not change > contents. Does anybody have an idea why? > > Regards, > > Harm de Laat > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060114/bf5aba3a/attachment-0001.html
On 1/13/06, Harm de Laat <harmdelaat@gmail.com> wrote:> def get_brands_for_category > @brands = Brand.find_all_by_category_id (@params["category_id"]) > end > > Somehow it does not work. The related dropdown list does not change > contents. Does anybody have an idea why?Make sure you have a get_brands_for_category.rhtml file like: <%= options_from_collection_for_select @brands, "id", "name" %> And you''ll want to turn off the layout for the get_brands_for_category action.
Try putting the second <select> inside a <div id="brand_id_container"> and return the entire select from your action.You would need a render partial or a render text which spews out HTML Vivek On 1/14/06, Harm de Laat <harmdelaat@gmail.com> wrote:> > Hi all, > > I''m trying to create a related dropdown box: > > In my view: > > <select name="category" id="category"> > <option value="">Select category</option> > <% @categories.each do |category| %> > <option value="<%= category.id %>"> > <%= category.title %> > </option> > <% end %> > </select> > > <select id=''brand_id_container'' name=''brand_id_container''> > <option value=''''>No Brand</option> > <% for brand in @brands -%> > <option value=''<%= brand.id %>''><%= brand.title %></option> > <% end -%> > </select> > > <%= observe_field("category", > :frequency => 0.25, > :update => "brand_id_container", > :url => { :action => :get_brands_for_category }, > :with => "''category_id=''+value") %> > > In my controller: > > def get_brands_for_category > @brands = Brand.find_all_by_category_id (@params["category_id"]) > end > > Somehow it does not work. The related dropdown list does not change > contents. Does anybody have an idea why? > > Regards, > > Harm de Laat > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060115/1bdefbbc/attachment.html