`

fdasfadsfdsa

阅读更多
asdfas
分享到:
评论
32 楼 yuan 2010-07-08  
http://chunyemen.org
这个标签“云”蛮不错。
31 楼 yuan 2010-06-09  
http://fsjoy.blog.51cto.com/318484/240417
Rails tips: 怪异的ActionController::InvalidAuthenticityToken

似乎Rails2.3.8中又出现了类似的问题。看来没人维护的东西还是早点扔掉好。
30 楼 yuan 2010-06-08  
29 楼 yuan 2010-06-04  
27 楼 yuan 2010-05-06  
于是我决定不折腾Factory_Girl,改用fixture……
26 楼 yuan 2010-05-06  
user has one store
store has many products
store has many catalogs
products has and belongs to many catalogs
catalogs has and belongs to many products

user has many products through store
user has many catalogs through store

在Factory girl中有如下定义:
Factory.with_options :class => Catalog do |factory|
  factory.define :pets do |catalog|
    catalog.name 'pets'
    catalog.products {|p| [p.association(:cat)]}
  end

  factory.define :books do |catalog|
    catalog.name 'books'
    catalog.products {|p| [p.association(:the_ruby_way)]}
  end
end

Factory.with_options :class => Product do |factory|
  factory.define :the_ruby_way do |p|
    p.name 'the_ruby_way'
    p.sell_price 94
  end

  factory.define :cat do |p|
    p.name 'cat'
    p.sell_price 500
  end
end

结果cat.catalogs.size为0。如果改成这样:
Factory.with_options :class => Product do |factory|
  factory.define :the_ruby_way do |p|
    p.name 'the_ruby_way'
    p.sell_price 94
  end

  factory.define :cat do |p|
    p.name 'cat'
    p.sell_price 500
    p.catalogs {|c| [c.association(:pets)]}
  end
end

又会死循环……  
24 楼 yuan 2010-04-19  
usage:
$('form').ajax_upload(function(response){
  $('#target').replaceWith(response);
  //or $('#target').append(response);
  //.......
});
23 楼 yuan 2010-04-19  
(function($){
  $.fn.ajax_upload = function(callback){
    if(this.attr('tagName') == 'FORM' && this.find('input[type=file]').size() > 0){
      this.attr('target', 'upload_frame')
      .submit(function(event){
        $('body').append("<iframe id='upload_frame' name='upload_frame' style='width:0px;height:0px;border:0px;display:none;' src='about:blank'></iframe>");
        $('body').append("<div id='frame_monitor' style='width:0px;height:0px;border:0px;display:none;'><script type='text/javascript'>"+
        "var _id = setInterval(function(){"+
          "var response = $('#upload_frame').contents().find('body').html();"+
          "if(response != ''){"+
            "clearInterval(_id);"+
            "("+callback+")(response);"+
            "$('#upload_frame').remove();"+
            "$('#frame_monitor').remove();"+
          "}"+
        "},300)"+
        "</script></div>");
      });
    }
  };
})(jQuery);
22 楼 yuan 2010-04-09  
:skip改为:skip_dir_name,值为正则表达式。
另外添加一个:skip_file_name。
类名还是改为FileTool吧。
21 楼 yuan 2010-04-08  
不会用Ruby编辑文件,又不会用Linux过滤指定文件夹,干脆把2者结合起来用……

require 'pathname'

class DirTool

  def initialize(dir)
    raise "\"#{dir}\"不是一个目录" unless File.directory?(dir)
    @dir = Pathname.new(dir)
  end

  #options
  #:skip => 要跳过的文件夹
  def recur_files(options, &block)
    @dir.children.each do |file|
      if file.directory? 
        next if file.basename.to_s == options[:skip]
        DirTool.new(file).recur_files(options, &block)
      else
        if block_given?
          block.call(file)
        else
          puts file
        end
      end
    end
  end

  def recur_replace(source, target, options)
    recur_files(options) do |file|
      `sed -i "s/#{source}/#{target}/g" #{file}`
    end
  end

end

DirTool.new('/home/yuan/workspace/projects/work/rails/reservation/app/views')
  .recur_replace('remove_class_name', 'remove_class', :skip => '.svn')
19 楼 yuan 2010-02-26  
关键字 ajax实战 svn
18 楼 yuan 2010-02-25  
关键字 debugfs ext3grep r-linux
17 楼 Saito 2009-10-27  
15 楼 Hooopo 2009-10-20  
自行车 写道
有点像“贾君鹏回家吃饭”的贴。只是你有了内容。

啊松岛枫,啊松岛枫..
14 楼 yuan 2009-10-19  
自行车 写道
有点像“贾君鹏回家吃饭”的贴。只是你有了内容。

13 楼 自行车 2009-10-19  
有点像“贾君鹏回家吃饭”的贴。只是你有了内容。

相关推荐

Global site tag (gtag.js) - Google Analytics