作者:老王
Rails升级到2.0.2,发现以前的Depot无法运行了:
class AdminController < ApplicationController
scaffold :product
end
出错信息:
undefined method `scaffold' for AdminController:Class
这是因为新版的Rails已经把scaffold剥离为插件,安装scaffolding插件
还是无法运行:
undefined method `paginate' for #<AdminController:0x33243dc>
这是因为scaffolding插件里使用的还是老式的分页方式,接着安装classic_pagination插件
列表可以运行了,但是在执行添加的时候,出现很诡异的情况:IE操作正常,但是FF就不行:
config.action_controller.allow_forgery_protection = false
不过为啥开始FF不行我还是没明白,以后有功夫看源代码是怎么写 的。
如果不知道怎么安装插件,建议使用Netbeans操作,非常简单,另外,建议阅读我以前的 相关文章。
-----------------------------------------------------------------------
如果想生成静态的脚手架,用法和老版有所差别,新用法生成的代码相当RESTFul,命令:
`./script/generate scaffold post` # no attributes, view will be anemic
`./script/generate scaffold post title:string body:text published:boolean`
`./script/generate scaffold purchase order_id:integer amount:decimal`
具体可以看相关源代码,在我的电脑里,源代码路径如下:
C:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/rails_generator/generators/components/scaffold
Rails升级到2.0.2,发现以前的Depot无法运行了:
class AdminController < ApplicationController
scaffold :product
end
出错信息:
undefined method `scaffold' for AdminController:Class
这是因为新版的Rails已经把scaffold剥离为插件,安装scaffolding插件
还是无法运行:
undefined method `paginate' for #<AdminController:0x33243dc>
这是因为scaffolding插件里使用的还是老式的分页方式,接着安装classic_pagination插件
列表可以运行了,但是在执行添加的时候,出现很诡异的情况:IE操作正常,但是FF就不行:
ActionController::InvalidAuthenticityToken搜索了一下才发现此问题是由于最新的 protect_from_forgery功能引起的,解决方法很简单,在对应的环境配置文件里加入下面语句即可:
config.action_controller.allow_forgery_protection = false
不过为啥开始FF不行我还是没明白,以后有功夫看源代码是怎么写 的。
如果不知道怎么安装插件,建议使用Netbeans操作,非常简单,另外,建议阅读我以前的 相关文章。
-----------------------------------------------------------------------
如果想生成静态的脚手架,用法和老版有所差别,新用法生成的代码相当RESTFul,命令:
`./script/generate scaffold post` # no attributes, view will be anemic
`./script/generate scaffold post title:string body:text published:boolean`
`./script/generate scaffold purchase order_id:integer amount:decimal`
具体可以看相关源代码,在我的电脑里,源代码路径如下:
C:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/rails_generator/generators/components/scaffold