here is the .js file:
function ajaxSearch(){
$("#prod").keyup(function(){
var product_id = $("#prod").val();
ajaxObject =$.ajax({
type:"GET",
dataType:'json',
url:'/products/product_info',
data:{product_id: product_id}
});
var results = jQuery.parseJSON(ajaxObject.responseText);
$("#results").html(results);
});
};
in my controller:
def product_info
if params[:product_id]
@product = Product.find_by_id(params[:product_id])
puts "this is the product title : #{@product.title}"
respond_to do |format|
format.js {render json: @product}
end
end
end
and the html part:
<form action="/products/product_info" onsubmit="return false;" onkeyup="ajaxSearch(); return false"> <input id ="prod" type="text" value="" placeholder="some text..."/> </form> <div id="results"></div>
When i look at console in the terminal everything is fine, ajax is working and its getting the correct products (the puts is in there to test it was working), but i'm sure how to render. I tried doing a render :partial => /products/show but in the terminal it kept saying missing template. which didn't make sense to me because rails automatically makes that for you. So I am lost right now.

New Topic/Question
Reply



MultiQuote



|