开发者

rails + escape_javascript + locales

I have the bel开发者_开发问答ow jquery script and I can't pass i value into locales=> :val

$(document).ready(function(){

  var i = 1

  function more(){

     var information= $("<%= escape_javascript(render :partial => 'info', :locals => { :val => i }) %>");

     i = i+1;
  }

});

Please guide me how to pass javascript variable to rails.

Thanks


If possible values of the variable i are limited, you could generate javascript for every possible value of i. e.g.: (i is in range 1..10)

$(document).ready(function(){
  var i = 1
  var informationArray = new Array();
  <% (1..10).each do |num| %>
    informationArray[<%= num %>] = $("<%= escape_javascript(render :partial => 'info', :locals => { :val => num }) %>");
  <% end %>

  function more(){
    var information = informationArray[i];
    i = i+1; 
  }

});

Otherwise, if variable i is not limited in a specific small range, you should use AJAX to send the parameter to the server and retrieve the information for that value.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜