题
我工作的一个轨道的项目。使用标记observe_field,我把文字输入一个文本区域处理这一控制,并显示结果的div(非常类似于预览堆溢)。一切正常,直到我某些类型的特殊字符。
- ?=>引起的变量不被发现在params对象
- (磅)=>导致无效的真实性的错误
- %=>停止div从正在更新
- &=>每一件事情之后&是没有再通过入变量的服务器。
有没有办法解决这个?
---代码样本---
这是图。('postbody'是一个文本地区)
<%= 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 => "'postbody=' + encodeURIComponent(value)"
然后在你的控制器:
def textile_to_html
text = URI.unescape(params['postbody'])
...
其他提示
你能提供一个代码样本?
更有可能比不你只是需要逃避你HTML实体使用 encodeuri 或者类似的东西。
什么所产生的Javascript看起来像什么?
听起来(乍)喜欢这不是逃跑了。
不隶属于 StackOverflow