i’m trying to pass a javascript variable into the ruby on rails 「 url_for」method
is that possible??
<a href="<%= url_for(:controller => 'epgs', :action => 'show', :parameter1 => myJavaScriptVariable %>" data-inline="true">
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, JavaScript variables are not in the scope when your ERB is being rendered as this is being done server-side. Javascript can only be used once the page has been fully rendered by Rails and returned to the user (i.e in the user’s browser). If you really need a JavaScript variable in the URL then a simple way to do it would be to add the extra parameter to the href using JavaScript once the page has loaded:
using jQuery or something similar.