Reputation: 11
How to use ruby and javascript mixing?
For example:
<div>
$(".pop-up-confirm").click( function(e) {
var domain_name = $("input#domain_name")[0].value;
var msg = #{call_ruby_function(domain_name)};
}
</div>
First, I use js to get the value domain_name
from input.
Second, I want call ruby_function
, use domain_name
as parameter.
The first step is correct, but I how to make the second correct.
Upvotes: 1
Views: 121
Reputation: 1227
To solve your issue you should perform AJAX request.
$.get('/some-path', { domain: domain_name }, function(data) {
# data is your message
});
Ruby code will be executed in server-side and your message should be returned to you to work with in client-side
My example requires jQuery to be available
Upvotes: 1
Reputation: 5155
You cannot execute ruby in the browser. You can only execute javascript. You can either rewrite your function in javascript, or make a request to your ruby server.
Upvotes: 3