I have a form for editing profiles. Rails automatically generates the form id as 'edit_profile_##' where ## is the profile id of the current user(instance variable-@profile_id). I need to use this form id for my javascript functions. Is there a way to get the current user's profile id inside js? Or is there a way I can override the automatic id generation by rails?
you have to send that using function parameter
.html.erb
<script type="text/javascript">
   var user_id = <%= @profile_id %>; // for integer
   var user_name = '<%= @profile_name %>'; // for string
   abc(user_id)// this is your function in .js file
</script>
.js
 function abc(id){
   alert(""+id)
 }
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With