In my Rails app I have many categories that have many clients. It also supports switching languages.
The categories are shown in the navigation of the app and I want to make a custom dropdown that contains the clients of that category. It will be created when a user hovers on some of those categories.
I've created a new resource that is doing the job of fetching the clients that belong to the hovered category, but I'm having trouble making those clients linkable due to the internationalization.
This is the javascript code:
$(function () {
$(".nav_category").hover(function () {
category_dropdown = $(this).children(".category_dropdown");
clients_from_category = category_dropdown.children(".clients_from_category");
category_dropdown.toggle(0, "hidden");
$.get($(this).data("url"), function(response) {
client_name = response[0]['translations'][0]['name'];
client_picture = response[0]['pictures'][0]['image']['thumb']['url'];
html = "<a href='/clients/"+response[0]['id']+"' class='nearest_client'>";
html += "<img src='" + client_picture +"'>";
html += client_name;
html += "</a>";
clients_from_category.html(html);
});
}, function() {
$(this).children(".category_dropdown").toggle(0, "hidden");
})
});
The problem here is that I get the links displayed like this:
<a href="/clients/157" class="nearest_client">
<img src="/uploads/picture/image/361/thumb_image.jpg">Client name
</a>
Notice there is no locale set. It should be like:
<a href="en/clients/157">
Is there a way to get to the set locale? Or am I approaching this problem in a bad way? What is a better way of setting a listener on a div and creating the needed DOM elements from the returned JSON object?