Use javascript variables in Rails view helpers
        Posted  
        
            by Horacio
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Horacio
        
        
        
        Published on 2010-05-31T04:14:22Z
        Indexed on 
            2010/05/31
            4:22 UTC
        
        
        Read the original article
        Hit count: 334
        
Using jqGrid I want to generate delete links for each row in the grid. The standard way to do this is to add the links in the gridComplete callback like shown below:
gridComplete: function() {                                                                                                                                      
  var ids = jQuery("#jobs_table").jqGrid('getDataIDs');                                                                                                         
  for(var i=0;i < ids.length;i++){                                                                                                                              
    var cl = ids[i];                                                                                                                                            
    be = '<%= link_to(image_tag("delete.gif", :border=>0, :size=>"20x22", :alt => "delete"),·                                                                   
              { :action => 'destroy', :id => 'cl', :method => :delete}, :class => 'ajax')  -%>';                                                        
    jQuery("#jobs_table").jqGrid('setRowData',ids[i],{workflow_state:be});                                                                                      
  }                                                                                                                                                             
},                                                                                                                                                              
Using getDataIDs I get a list of IDs that I can use to generate the delete links. The problem is that this is a javascript call that results in a javascript variable.
The question is how can I use this variable "cl" inside rails link_to view helper?
© Stack Overflow or respective owner