Thats the way it is baby!
jquery
},
initSelection : function (element, callback) {
var data1 = [];
jQuery(element.val().split(",")).each(function () {
$.ajax({
type: "get",
url: "/providers/list_categories",
async: false,
dataType: 'json',
data: { id: $("#provider_id").val()},
success: function(category){
$.each(category, function(i, obj) {
data1.push({id: this._id, text: this.title});
});
}
});
});
callback(data1);
}
});
contoller
def list_categories
@provider = Provider.find params[:id]
arr = @provider.category.split(",")
@category = Category.where(:_id.in => arr)
respond_to do |format|
format.json { render :json => @category}
end
end