How to use javascript variables in ruby

前端 未结 2 600
清歌不尽
清歌不尽 2020-12-20 05:57

I\'m new in rails and I want to use a javascript variable into ruby embedded code to make a query in the database,

This is my code

function modify()         


        
2条回答
  •  佛祖请我去吃肉
    2020-12-20 06:29

    Since Ruby is a Server based language like php or asp/asp.net, using code from the server in the page is very easy like printing it, so if you want to change a javascript variable using server side values is easy. However doing the opposite is a different thing. I would send those values to the server using a proxy call (jQuery most likely). The solution you are asking for calls for the use of a javascript framework like jQuery, not rails that I know.

    Try using a jQuery ajax proxy and refreshing data in the client based on server´s response, that will do the trick.

    check http://www.jquery.com, use rails to create services that will respond with JSon to your queries.

    I hope this help.

提交回复
热议问题