开发者

pass a javascript variable as a param in url_for

开发者 https://www.devze.com 2023-02-01 02:03 出处:网络
i\'m trying to pass a javascript variable into the ruby on rails 「 url_for」method is that possible??

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') + '&parameter_1=' + myJavaScriptVariable;
  $('#link').attr('href', new_link);

using jQuery or something similar.

0

精彩评论

暂无评论...
验证码 换一张
取 消