开发者

rails code within javascript

开发者 https://www.devze.com 2022-12-24 09:18 出处:网络
I am trying to use some rails code withing a javascript and need to have that rails code be dynamically changed.Here\'s the line of code:

I am trying to use some rails code withing a javascript and need to have that rails code be dynamically changed. Here's the line of code:

$(this).replaceWith("<%= escape_javascript(render(:partial => 'shared/products')) %>");

The 'shared/products' is the part I want to change based off information passed earlier in the javascript. How do I insert a value from javascript so that instead of 'shared/products' the products portion can be a variable? Hope this makes sense. I'm not the most experienced jQuery/javascript programmer, so any help is very muc开发者_运维百科h appreciated. Thanks in advance!


No, you cannot do that way. rails codes may run on page loads, but when you write those with javascript, those are just texts. If you really need to run server side scripts, use AJAX.

0

精彩评论

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