0

I am created Rail application with erb views. I want to use some JS code with in ruby code like following

<script>
   $('#select-service').click(function() { 
      var service='<%= Service.find("this.id") %>';
    });
</script>

I want to query based on user selected value. How to replace "this.id" used above and how to insert js code instead of "this.id" ?

1
  • I recommend using Ajax for such task, If you explain your case better maybe I could help Commented Oct 18, 2016 at 10:37

1 Answer 1

1

You cant. this is only available in the browser.

One of the option you can do is to do it via ajax.

for example.

<script>
   $('#select-service').click(function() { 
      $.get('/service/' + this.id, function(result){
           service = result;
     }
    });
</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.