All the other solutions in stackoverflow doesn't seem to work for me so i'm posting my code for assistance. I want to output the variable: @less_per_unit via jquery
Here is my tag inside _form.html.erb:
<script>
$(document).on('keyup', ".input-quantity", function(){
$.ajax({
url: "/so_check_increment",
type: "GET",
data: { quantity: $(this).val(), product_id: $(this).closest('tr').find('.input-product_code').val()}
});
$(this).closest('td').next('td').find('.increment').text('<%== j @less_per_unit%>');
});
</script>
And here is my controller:
def check_increment
@less_per_unit = "testing"
end
I know that the ajax works, i've also set up the routes. If I try binding.pry, I know that rails can find @less_per_unit, but I can't output it with javascript.