---
title: "rails 升级到2.2你可能会遇到的问题及解决方法"
author: "arkxu"
date: "2008-11-23T13:56:47Z"
tags: ["Google", "MySQL", "Rails", "Ruby", "rubygems"]
categories: ["编程语言"]
slug: "rails-2-2"
draft: false
lastmod: "2008-11-23T14:03:49Z"
id: 275042
url: "https://arkxu.iteye.com/blog/275042"
---

昨晚升级了2.2，遇到了一堆的问题。我相信大家多多少少都会遇到。而且google无门，翻遍了找不到解决方法。只能自己动手了。希望大家可以少走弯路。 1. 在generate path的时候，比如 user\_path(@user)的时候，总是遇到 can not convert fixnum to String 解决: 检查你所有model上的to\_param方法，看看是否有数字类型返回，如果有将其改成String 2. 如果你用了restful authentication 的话，你可能会遇到当用户注册的时候，通过email发出的activation\_code和数据库里存的不一样。 解决方法1：这个问题非常蹊跷，user\_observer里看不出任何问题。倒是activation\_code的产生方法是时间相关的，如果你改成一个固定字符就不存在此问题，说明user\_observer里用的不是db里的值，那么就在observer的每一个事件之后都加上:user.reload 解决方法2: 上面的解决方式实在无语。后来我把db/schema.rb删了，重新migrate。问题消失。 3. theme\_support 不工作了。 解决方法：theme\_support hack了action view的rend\_file方法，这个方法在2.2中已经不存在了。最简单的修改方法是： \[code="rb"] alias\_method :theme\_support\_pick\_template, :\_pick\_template # Overrides the default `Base#render_file` to allow theme-specific views def \_pick\_template(template\_path) search\_path = \[ "#{RAILS\_ROOT}/themes/#{controller.current\_theme}/views", # for components "#{RAILS\_ROOT}/themes/#{controller.current\_theme}", # for layouts "#{RAILS\_ROOT}/app/views", ] self.view\_paths = search\_path theme\_support\_pick\_template(template\_path) end \[/code] 同样，修改过的action mailer的 render方法： \[code="rb"] def render(opts) body = opts.delete(:body) body\[:current\_theme] = @current\_theme if opts\[:file] && (opts\[:file] !~ /\\// && !opts\[:file].respond\_to?(:render)) opts\[:file] = "#{mailer\_name}/#{opts\[:file]}" end begin old\_template, @template = @template, initialize\_template\_class(body) layout = respond\_to?(:pick\_layout, true) ? pick\_layout(opts) : false @template.render(opts.merge(:layout =&gt; layout)) ensure @template = old\_template end end \[/code] 4. xss\_terminate 不工作了。出问题的语句很奇怪:self\[field] = RailsSanitize.full\_sanitizer.sanitize(value) 而RailsSanitize是完全include ActionView::Helpers::SanitizeHelper。所以它报错说什么full\_sanitize不存在简直就是莫名。还请高人指点一二。 解决方法：遇到RailsSanitize的地方就改成HTML::FullSanitizer.new 5. engines plugin 挂了 解决方法：其实仔细想想我是不是真的需要它了。我只用到了一个plugin是model在plugin里面的，那么我就把这些model cp到app/model下面了。把engines删了干干净净的。心情也好了很多！ 6. 用macos的朋友才会有。rails 2.2把db adapter拿掉了，一定要求你用比如mysql gem. 如何在苹果上面安装呢？ 解决方法：sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql\_config