Rails查找条件从字段中删除前2个符号

时间:2012-10-26 17:37:23

标签: ruby-on-rails ruby activerecord

我有这样的AR代码:

@types = Type.find(:all, 
             :conditions => { :TYP_MOD_ID => params[:models],
                              :TYP_PCON_START => params[:year] }, 
             :order => "TYP_HP_FROM")

但我怎么能这样做,我看到TYP_PCON_START没有前2个符号并进行比较? 例如:TYP_PCON_START.to_s[4...6]

另外我需要比较not =,但是> =>条件。怎么做?

1 个答案:

答案 0 :(得分:1)

使用where代替find。我也不明白你的意思how can i do that i see TYP_PCON_START without first 2 symbols and compare?

@types = Type.where("TYP_MOD_ID = ? AND substring(TYP_PCON_START FROM 4 to 6) >= ?", 
  params[:models], params[:year]).order("TYP_HP_FROM")