Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
js.erb模板中的Rails 3 jquery正在创建转义html?_Jquery_Ruby On Rails_Ruby On Rails 3 - Fatal编程技术网

js.erb模板中的Rails 3 jquery正在创建转义html?

js.erb模板中的Rails 3 jquery正在创建转义html?,jquery,ruby-on-rails,ruby-on-rails-3,Jquery,Ruby On Rails,Ruby On Rails 3,在Rails 3中,我有一个update.js.erb模板,其中有一行简单的jquery: $("#some_div").html("<strong>some_content</strong>"); $(“#some_div”).html(“some_content”); 提交表单后,所有ajaxy内容都正常工作,但是#some_div中的内容将被替换为“some_content”,而不是some_content。有人知道为什么吗 这在Rails 2中运行良好。提前谢

在Rails 3中,我有一个update.js.erb模板,其中有一行简单的jquery:

$("#some_div").html("<strong>some_content</strong>");
$(“#some_div”).html(“some_content”);
提交表单后,所有ajaxy内容都正常工作,但是#some_div中的内容将被替换为“
some_content
”,而不是some_content。有人知道为什么吗

这在Rails 2中运行良好。提前谢谢你的帮助


更新(半解决):愚蠢的我,仍然有jquery.form插件挂在身边,它不能神奇地发挥作用。看来我又要把东西撕成碎片了。。。谢谢大家的帮助。

如果您使用的是jQuery 1.4,请尝试

$('#some_div').html(function(i,v){
    return $('<strong>').html('some_content');
});
$('some#div').html(函数(i,v){
返回$('').html('some_content');
});

(另外,我喜欢javascript上的单引号)

欢迎来到SO,请不要忘记访问您使用的是
.html()
还是
.text()
?另外,您是否确定返回的内容没有经过编码,例如
strong
?肯定是使用.html()。。。内容可能是编码的,但我认为这是由于Rails 3的魔力,我显然没有完全理解。我已经准备好jquery.rails.js文件和我的助手,等等。但是没有乐趣。谢谢Reigel。。。我认为我的问题是由于一些Rails3编码/安全字符串魔法,我没有得到。您的代码给了我一个错误:语法错误,无法识别的表达式:strong@jonphillips-这肯定是rails对其进行编码,而不是客户端问题…需要弄清楚它为什么对脚本进行编码。