in_place_editor for rails2.0.2
Posted by devon on March 15th, 2008 filed in Pluginin_place_editor使用:
1 2 3 4 5 6 7 8 9 10 | script/plugin install in_place_editing # Controller class BlogController < ApplicationController in_place_edit_for :post, :title end # View <%= in_place_editor_field :post, 'title' %> </code> |
在rails2.0及以上版本使用时,出现如下错误:
ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken)
解决办法
修改
vendor/plugins/in_place_editing/lib/in_place_macros_helper.rb
1 2 3 4 5 6 7 8 9 10 11 | 42a43,46 > if protect_against_forgery? > options[:with] ||= "Form.serialize(form)" > options[:with] += " + '&authenticity_token=' + encodeURIComponent('#{form_authenticity_token}')" ? end 53c57,58 # js_options['evalScripts'] = options[:script] if options[:script] > js_options['htmlResponse'] = !options[:script] if options[:script] 55a61 > js_options['textBetweenControls'] = %('#{options[:text_between_controls]}') if options[:text_between_controls] </code> |
修改后的文件为 http://cookbook.enjoyrails.com/cookbooks/20
更新: github上最新的in_place_editing已支持authenticity_token
cd vendor/plugins
git clone git://github.com/rails/in_place_editing.git
Related posts:
- in_place_editing Rails 2中in_place_editing被抽出成为一个单独的插件;而prototype库则升级为1.6.0.1。一些由以前版本升级至2.0版本的Rails应用的in place editing功能,若使用了:script => true选项就会出错,表现为编辑完成后,编辑框内文字显示为一段Javascript代码而非输入的内容。如下面的用法: 造成这个错误的原因,是Prototype1.6中去除了evalScripts选项,而这个选项即是由in_place_editor_filed中的:script来指定的。Prototype中加入了一个新的选项htmlResponse,其含义与evalScripts恰好相反。 找到了问题的根源,解决方法便有了,修改vender/plugins/in_place_editing/lib/in_place_macros_helper.rb,将给evalScripts赋值的一行改掉便可: #js_options[’evalScripts’] =...
Related posts brought to you by Yet Another Related Posts Plugin.
Leave a Comment