How to dynamically assign form id to jquery function in rails with erb

77 views Asked by At

I'm implementing Ace text editor into a form partial that I'm using for all my settings. The form id is something like "edit_setting_#{@setting.id}". I've got the text editor substituting for the field and it works perfectly when I hard-code the form id. How do I set it dynamically?

<script>
$(document).ready(function(){ 
  var editor = ace.edit('editor'); 
  editor.setTheme('ace/theme/twilight');  
  $('#setting_value').hide(); 
  $("#edit_setting_16").submit(function(){ 
  $('#setting_value').val(editor.getSession().getValue()); 
  }); 
  });
</script>
1

There are 1 answers

0
Josh Hunter On BEST ANSWER

I was over-complicating it.

<script>
$(document).ready(function(){ 
  var editor = ace.edit('editor'); 
  editor.setTheme('ace/theme/twilight');  
  $('#setting_value').hide(); 
  $("#edit_setting_<%= @setting.id %>").submit(function(){ 
  $('#setting_value').val(editor.getSession().getValue()); 
  }); 
  });
</script>