<script type="text/javascript">
$(document).ready(function() {
var school_name = $('input#search_school_name_like').val();
});
</script>
In my erb file, I need to check,
If school_name is not nil?
<%= link_to "link" students_path(:range => 'A-B',:school_name => school_name) %>
else
<%= link_to "link" students_path(:range => 'A-B) %>
How to communicate between javascript and erb file? Pls help.
Javascript code is executed in user’s browser, and
ERBfile is being processed on server. That means you cannot use Javascript variables in Ruby code. So the code likelink_to "link" students_path(:range => 'A-B',:school_name => school_name)won’t work. You have to create a path manually in Javascript: