Topic: rails code inside jq.validation for multiple controller

Hello people, i am moving and applications to 3.2 so i have a form and that for is for multiple controllers and i need to validate some fileds, but the id of each field is created depending on the controller, so i need to put some rails code inside the validation.

Teh problem is that i don't know where to put the code, because i can't be inside the responde_to if @controller.save because is valiating and in these case the actions save.
it can't be in assets because it does not acept rails code

for example my name fild id is somethng like 

name     = $('#<%f.contorller_name%>_name').val();

any advise where to put these code???

at these time it is inside my view inside <script> tags but i want to move it from there