Is there anything wrong with setting a Rails variable inside a javascript function? I haven't been able to google a definete answer and just wanted to make sure there's not a catch or flaw I'm unaware of. I'm actually confused as to how this works at all - if javascript is executed on the client side, I wouldn't have assume Rails would respond to a variable change in the view after the view is rendered..?
(example) I have multiple functions calling the same form and I have a need to know which function called the forms to do specific tasks in the controller method (session in this case is a cookie, but I also tried a local Rails variable and it works as well).
<script type="text/javascript">
$('.open_new_item_form' ).click(function(){
alert('<%= session[:item_form_type]%>');
<% session[:item_form_type] = "from_new_item_click" %>
alert('<%= session[:item_form_type]%>');
var url = $(this).attr("href");
$.ajax({
etc...
The alerts seem to indicate it works well. It will alert with the current valute and then the new "from_new_item" value after the set.
Thanks - just making sure