Reputation: 1362
I am created Rail application with erb views. I want to use some JS code with in ruby code like following
<script>
$('#select-service').click(function() {
var service='<%= Service.find("this.id") %>';
});
</script>
I want to query based on user selected value. How to replace "this.id" used above and how to insert js code instead of "this.id" ?
Upvotes: 0
Views: 451
Reputation: 2032
You cant. this
is only available in the browser.
One of the option you can do is to do it via ajax.
for example.
<script>
$('#select-service').click(function() {
$.get('/service/' + this.id, function(result){
service = result;
}
});
</script>
Upvotes: 1