RSS
热门关键字:  java  Ajax  JSP  JSF  Struts
当前位置 : 首页>Ruby>列表

Rails宝典之第二式: 动态find_by方法

来源: 作者: 时间:2007-09-19 点击:
  •   
  •       when Hash   
  •         finder_options = extra_options.merge(:conditions => attributes)   
  •         validate_find_options(finder_options)   
  •         set_readonly_option!(finder_options)   
  •   
  •         if extra_options[:conditions]   
  •           with_scope(:find => { :conditions => extra_options[:conditions] }) do  
  •             ActiveSupport::Deprecation.silence { send(finder, finder_options) }   
  •           end   
  •         else  
  •           ActiveSupport::Deprecation.silence { send(finder, finder_options) }   
  •         end   
  •   
  •       else  
  •         raise ArgumentError, "Unrecognized arguments for #{method_id}: #{extra_options.inspect}"  
  •     end   
  •   elsif match = /^find_or_(initialize|create)_by_([_a-zA-Z]\w*)$/.match(method_id.to_s)   
  •     instantiator = determine_instantiator(match)   
  •     attribute_names = extract_attribute_names_from_match(match)   
  •     super unless all_attributes_exists?(attribute_names)   
  •   
  •     if arguments[0].is_a?(Hash)   
  •       attributes = arguments[0].with_indifferent_access   
  •       find_attributes = attributes.slice(*attribute_names)   
  •     else  
  •       find_attributes = attributes = construct_attributes_from_arguments(attribute_names, arguments)   
  •     end   
  •     options = { :conditions => find_attributes }   

  • 共3页: 上一页 [1] 2 [3] 下一页
    最新评论共有 0 位网友发表了评论
    发表评论
    评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
    用户名: 密码:
    匿名?
    注册
    Google Adsense
    相关文章