@coupon_id = params[:id]
end
Here the problem is i need to get the params[:id] in controller. so when
the act button click in view, that will call the ajax through class .*
actcpn,* where i give the url to the controller,How to pass that button
id
via that ajax url to controller?
i have one button in pgm.html.erb, that button name is activate, so
when
i click on that button, that will call one ajax with the class id
(actcpn),
in that ajax function, i have specified the url: *
“http://localhost:3000/pgms/cpn_activate/”* to controller, In that
controller i have to get the button id, which i pass :id =>
params[:id],
through button…
So how to pass that button ID via the url from the ajax…?
On Wednesday, 23 May 2012 02:32:59 UTC-4, azizmb.in wrote: header.js
*
*
$(“.actcpn”).click(function() {
$.ajax({
type: “PUT”,
url: “http://localhost:3000/pgms/cpn_activate/”,
success: function(){
$(‘.nplabel’).fadeIn(300).show();
$(‘.nplabel’).fadeOut(3000);
}
});
});
…
So how to pass that button ID via the url from the ajax…?
You pass the parameter the same way you always do with HTTP. Put it in
the query string or request body. JQuery makes this easy using the
“data” attribute:
You pass the parameter the same way you always do with HTTP. Put it in
the query string or request body. JQuery makes this easy using the
“data” attribute:
data - A map or string that is sent to the server with the request.
I forgot one other possible location. The data/attribute could be part
of the URL itself, as is often the case with Rails routes (i.e. http://localhost:3000/pgms/cpn_activate/1#where 1 is the id).
P.S. That’s a pretty ugly URL for a Rails app by the way. Maybe you
should consider cleaning that up. Start with not abbreviating so much.
If “pgms” means “programs” then have a Program model and
“/programs/:action/:id” for the route. Search engines will also
appreciate having actual words in the URL. The more clear the intent the
better. We’re not in danger of running out of letters on the web.