I feel really dumb and ashamed. Just started learning jQuery and got stuck at the first day. Basically, I am building all of this in ruby on rails, and I have a list of clients with basic info like name, address, phone number, etc. In the picture below is my page layout (yes, I know.. born artist).
In the left table, I display all the clients I have in database, first column represents client's id and the second column shows their names. In the right table (it is a partial), I display full client's info. My objective is this: by clicking on the row, on the left table, the right table would update and show the info related to that client I selected. Here is what I tried:
<script>
$('#table_clients tbody').on('click', 'tr', function() {
$("#container_info").replaceWith(
'<%= j render :partial => "client_info", :locals => {:client => 1} %>'
);
});
</script>
Notice that I manually specified the client's ID. My question is, how can I identify which row I selected and pass the ID to the erb fragment ?
I can get the ID by calling this:
$(this).find(':nth-child(0)').text();
But dont know how to pass it inside erb fragment. What is the work around for this ? There are probably a better way than using replaceWith method, it was the first idea I got.