I have a js file where I want to pass some Rails variable to such as url. What I do is:
#main.haml.html
<script type="text/javascript">
var myUrl = <%=some_url%>;
</scirpt>
#script1.js
$.ajax({
method: 'POST',
url: myUrl,
success: function(data) {
//..........
},
error: function(a, b, c) {
//..........
}
});
I think it seems the proper way of doing this. Is this the idiomatic way of doing it? Is there a better way?