rails 升级到2.2你可能会遇到的问题及解决方法

昨晚升级了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中已经不存在了。最简单的修改方法是:

alias_method :theme_support_pick_template, :_pick_template
# Overrides the default <tt>Base#render_file</tt> 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


同样,修改过的action mailer的 render方法:

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 => layout))
ensure
@template = old_template
end
end


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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值