Hello, I am trying to do the classic category -> subcategory chained dropdowns (where selecting something in category, populates the subcategory).
The code I have works in all browsers except IE (naturally).
Here is the JS code I am using:
$("body select#category").data_binding({
child: "select#company_subcategory_id",
url: "subcategories",
});
[ . . . ]
data_binding: function(options)
{
$(this).change(function()
{
$.getJSON("/"+ options.url +"/",
{ id: $(this).val(), ajax: 'true'},
function(j)
{
for (var i = 0; i < j.length; i++)
{
options += '<option value="' + j[i].optionValue + '">';
options += j[i].optionDisplay;
options += '</option>';
}
$(child).html(options);
});
});
}
Subcategories controller
class SubcategoriesController < ApplicationController
layout 'application'
def index
@subcategories = Subcategory.find_all_by_category_id(params[:id])
respond_to do |format|
format.js {render :json => @subcategories.collect {|sc| {:optionValue => sc.id,
:optionDisplay => sc.name} }.to_json }
end
end
def show
@subcategory = Subcategory.category_permalink_like(params[:category]).
permalink_like(params[:subcategory]).first
@with_banner = @subcategory.companies.active.with_banner
@without_banner = @subcategory.companies.active.without_banner
end
end
I'm tailing the development.log file and when I use any browser except IE the log shows
Processing SubcategoriesController#show (for 192.168.1.70 at 2010-08-26 01:49:06) [GET]
Parameters: {"id"=>"4", "_"=>"1282805337516", "show_type"=>"available_banners"}
but when I use IE I get
Processing SubcategoriesController#create (for 192.168.1.70 at 2010-08-26 01:50:09) [POST]
Parameters: {"ajax"=>"true", "authenticity_token"=>"Eg2XAvSSHg/v12cKjTPt+HkKWhxdGW3s5n6lm9jHu2A=", "id"=>"6"}
There is no defined create action, so it crashes.
I have no idea why this is interpreted differently :/
Any suggestions?
Thanks!!