MetaSearch Gem - Rails 3.0 working scope methods fail in Rails 3.2

本小妞迷上赌 提交于 2019-12-11 10:37:16

问题


MetaSearch's handy functions such as .not_in worked in Rails 3.0 & 3.1 inside of scope calls.

I had to rewrite some scopes to be "plain Rails 3.2" without MetaSearch convenience even though MetaSearch works outside of scope. And it broke several of my apps & tools when I upgraded.

Ideas? I am using MetaSearch everywhere. Even wrote a custom predicate. Still could be missing something obvious I hope.

On Rails 3.2, working inside an engine for code separation. Didn't seem to matter when I tried to isolate to Vanilla-Rails with no namespace/subfolders or engines.

Note -- I just wrote my first customized "Where" predicate :gt_da for :greater_than_days_ago so :created_gt_da = 7 will search for records created >= 7.days.ago https://github.com/ernie/meta_search/wiki/Handy-way-to-develop-and-test-creating-a-new-%22Where%22-without-restarting-your-server-everytime

    class Bug < ActiveRecord::Base

      # MetaSearch
      search_methods :bug_active

      ## Rails 3.0 (and gems of that time) => 100%), 3.1 pretty sure
      ## Rails 3.2 error: "undefined method `not_in' for :resolution:Symbol"
      scope :bug_active, lambda {|checked| 
        where(:resolution.not_in => ['ERWITHPM','WONTFIX','WORKSFORME','DATAFIXDEPLOYED','PATCHDEPLOYED','RELEASEDEPLOYED','DUPLICATE','INVALID'] \
          , :bug_status.not_in => ['VERIFIED']  ) }

      ## Rewritten to work in Rails 3.2 without MetaSearch convenience inside of scope 
      ## ... a pinch more work which is why we love MetaSearch!
      scope :bug_active_why, lambda {|checked| 
           where("resolution not in (?)", ['ERWITHPM','WONTFIX','WORKSFORME','DATAFIXDEPLOYED','PATCHDEPLOYED','RELEASEDEPLOYED','DUPLICATE','INVALID'])
          .where("bug_status not in (?)", ['VERIFIED']  ) 
      }

    end          

    module Bugzilla
      class BugsController < ApplicationController

        @p = params[:search]

        ## MetaSearch works fine here on ":resolution_not_in" from form/search            
        @p[:resolution_not_in] = ['WONTFIX','WORKSFORME']

        @search = Bug
          .limit(50)
          .where("version like '2012_%p'")
          .search(@p)

      end
    end

来源:https://stackoverflow.com/questions/9858552/metasearch-gem-rails-3-0-working-scope-methods-fail-in-rails-3-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!