I have a JavaScript variable:
var selectValUser = $('.select_user :selected').val();
I need to use this variable in erb code on the same page, i.e
<%= get_free_hours_for_user(selectValUser) %>
How can I do it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You cannot do it because javascript run on client side while the code in ERB file runs at server side, you can send the value using ajax request,
Plus here is an awsome rails cast
Here is an example to send message from javascript to controller; When user click on apply we have an action ‘set_id’ in controller, it get the power, do the validations etc, the show the message in ‘id_message’ div in views.
Hope it would answer your question