Related drop down list / ajax


#1

Hi all,

I’m trying to create a related dropdown box:

In my view:

Select category <% @categories.each do |category| %> <%= category.title %> <% end %> No Brand <% for brand in @brands -%> <%= brand.title %> <% end -%>

<%= 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


#2

Anybody?


#3

Try putting the second inside a


and
return the entire select from your action.You would need a render
partial or
a render text which spews out HTML
Vivek

#4

On 1/13/06, Harm de Laat removed_email_address@domain.invalid 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.