ERB doesnt get executed in javascript scripts

Posted by Stefano on Stack Overflow See other posts from Stack Overflow or by Stefano
Published on 2010-08-11T19:25:10Z Indexed on 2011/01/13 8:53 UTC
Read the original article Hit count: 202

Hi guys

I have a select input on my page. this select input displays/hides fields in the form. This all works fine. But the problem is that if i submit the form and lack some necessary fields, it doesnt set the select to the right value afterwards. I just cant get the embedded ruby to work! it keeps escaping the whole thing... here my code:

$(document).ready(function() {
$("#profile_sex").val('<%= @profile.sex %>')
   $("#profile_sex").change(function(){



    ($(this).val() == "Frau") ? $('#form-female').show() : $('#form-female').hide();
    ($(this).val() == "Mann") ? $('#form-male').show() : $('#form-male').hide();
    if ($(this).val() == "Paar") {
        $('#form-female').show(); 
        $('#form-male').show();
    }       
  });

});

why doesnt this work??? I dont get any error or anything it just sets the value to "<%= @profile.sex =>" I was googling and searching about on stack overflow and railscasts, the rails API, everything. Im seriously confused...

thanks for your help.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about ruby-on-rails