<%= observe_field 'postbody', 
        :update => 'preview', 
        :url => {:controller => 'blog', :action => 'textile_to_html'}, 
        :frequency => 0.5, 
        :with => 'postbody' -%> 

这是被称为

def textile_to_html 
    text = params['postbody'] 
    if text == nil then 
     @textile_to_html = '<br/>never set' 
    else 
     r = RedCloth.new text 
     @textile_to_html = r.to_html 
    end 
    render :layout => false 
end 

控制器,这是生成的JavaScript:

new Form.Element.Observer('postbody', 0.5, function(element, value) {new Ajax.Updater('preview', '/blog/textile_to_html', {asynchronous:true, evalScripts:true, parameters:'postbody=' + value + '&authenticity_token=' + encodeURIComponent('22f7ee12eac9efd418caa0fe76ae9e862025ef97')})}) 

这是一个转义问题(如其他人所述)。

你想改变你的observe_field:with语句是这样的:

:with => "'postbody=' + encodeURIComponent(value)" 

然后在你的控制器:

def textile_to_html 
    text = URI.unescape(params['postbody']) 
    ... 

你可以提供一个代码示例?

更有可能你只需要使用encodeuri或类似的东西来逃避你的HTML实体。

生成的Javascript看起来像什么?

声音(乍一看)就像它没有被转义。

相关推荐