On some of my pages, I have a hash in the url like this: http://localhost/#/products/6959
How can I check if I have a product ID available and so I can save it in a variable to use later? Any help would be greatly appreciated!
You want a regexp to extract the number at the end of the url in javascript?
"http://localhost/#/products/6959".match(/[0-9]+$/);
Edit: Or if you want to make sure this is products:
"http://localhost/#/products/6959".match(/products\/([0-9]+$)/)[1]);
The parenthesis indicate a matching group that you find in [1].
You should be able to get that id out of the URL through accessing the params
variable. In this case, params[:id]
should do the trick.
Also, I do not recommend using a regex.