This is my ajax call
$.ajax({
type: "GET",
url: '/posts/product_list.json',
data: {sub_cat_id: parseNumber(sub_category_id)},
dataType: 'json',
success: function(data) {
//$('#selection').show();
$('#selection').html(data.html);
},
error: function(data){
}
});
I have the post_list controller
respond_to :json,only: :product_list
def product_list
@products = Product.where(sub_category_id: params[:sub_cat_id])
##blah blah blah
end
My url is showing like this while inspecting product_list.json?sub_cat_id=5
But the debugger is showing request parameter
as follows
{"sub_cat_id"=>"5", "action"=>"show", "controller"=>"posts", "id"=>"product_list", "format"=>"json"}
I am very much confused why this is happening can any one clear it.
It appears you don't have a corresponding route entry. You should have something like this in your routes.rb
:
resources :posts do
get :product_list, on: :collection
end
If you only specify resources :posts
, your GET request would match the one for GET /posts/:id
(look at the output of rake routes
), i.e. show
action of PostsController
with product_list
parsed as the id parameter in the request URI. get :product_list
defined after those 7 entries would make the router match the URI to the corresponding action and controller.