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', :parameter开发者_如何转开发1 => myJavaScriptVariable %>" data-inline="true">
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:
new_link = $('#link').attr('href') + '¶meter_1=' + myJavaScriptVariable;
$('#link').attr('href', new_link);
using jQuery or something similar.
精彩评论