2007年5月11日星期五

Fix theme_support in rails1.2.x

theme_support当前版本1.3.0不支持Rails1.2.x,需要修理一下方
可使用。

1、错误现象的产生:
执行下述命令:
./script/generate theme default
将安装theme_support到vender/plugins,且创建themes目录后生成
default theme。
再次生成另一个theme,比如:another
./script/generate theme another
将产生下述错误:
./script/../config/../vendor/plugins/theme_support/lib/
patches/routeset_ex.rb:26:in `create_theme_routes':
undefined method `named_route' for # (NoMethodError)

2、解决方法:
1)修改
vendor/plugins/theme_support/lib/patches/routeset_ex.rb
文件,将draw方法替换为下述内容:
  def draw
  clear!
  create_theme_routes
  yield Mapper.new(self)
  named_routes.install
end
在create_theme_routes方法中,
————替换named_route为add_named_route;
————替换connect为add_route。

也可以在这里下载修改好的theme_support包。

2)修改
vendor/plugins/theme_support/lib/patches/actioncontroller_ex.rb
文件,添加下述内容:
alias_method :__assert_existence_of_template_file, :assert_existence_of_template_file
def assert_existence_of_template_file(template_name)
  unless template_exists?(File.join( "../../themes/#{current_theme}", template_name))
    __assert_existence_of_template_file(template_name)
  end
end
上述方法在Rails1.2.3下测试通过。 参考: http://www.ruby-forum.com/topic/100163 http://www.mattmccray.com/pivot/archive.php?c=Theme_Support http://imaspy.com/news/read/5

没有评论: