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中已经不存在了。最简单的修改方法是: [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 => 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
你装mongrel了么?
e:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_re quire': no such file to load -- e:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86 -mswin32/lib/mongrel/init.rb (MissingSourceFile)
不好意思啊。。博主。。慕名前来。。请问。。我在升级了2.2.2以后出现了这个问题。 gem包也升级了,但是就是一直出现这个问题,。。请问。。怎么办啊。。
对于这个问题是由于在创建用户的时候两次生成activation_code,可以在user.rb里面加上