开发者

Rails 3 and jQuery- how to transmit ruby variable to javascript

开发者 https://www.devze.com 2023-03-24 04:59 出处:网络
I would like to ask you - I have javascript code and I need into this part of code transmit variable with data from database. This variable is in controller. How can I do it?

I would like to ask you - I have javascript code and I need into this part of code transmit variable with data from database. This variable is in controller. How can I do it?

I tried something like (in *.js):

$("#div").append('<%= escape_javascript(@test) %>hhhhhh');

or

$("#div").append('<%= @te开发者_运维知识库st %>hhhhhh');

But the codes above not works... Could you help me, please, how to do?

Thank you, Manny


If you are rendering a response to AJAX-call, that code should go in your_action.js.erb file. Otherwise, if it's just inline JavaScript, place it in your_action.html.erb under app/views/your_controller directory.

Correct me if I understood you wrong.

0

精彩评论

暂无评论...
验证码 换一张
取 消