I have created Ruby Session Variable
I need to access this variable in Javascript
Lets take this scenario
session[:note]
= 'Some Notes'
this is done in Ruby on Rails
Now I want to access this is like
var session_val = js-code for access above session variable.
its not js.erb I know if it is js.erb we can access like
var sesion_val = "<%= session[:note] %>"
TIA
You can use HTML5 data
method from where you can access the variable.
suppose, your JS
function is calling from a button.
thus, you can define that button as:
<button class="btn" data-session="<%= session[:note]%>" onclick="seesionCheck()">Hello</button>
now, in your JS
function you can access the variable as:
$(".btn").data('session');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With