Search code examples
ruby-on-railsruby-on-rails-3rails-activerecorddefault-scope

Default scope for production but not in development


I have a model which I want to limit the results to those of a particular client so client number 1 (my database contains other client data too)

so I have a scope like this:

default_scope {
  where(
    :owner_id => 1,
    :someother_criteria => false
  )
}

I want this scope (the :owner_id => 1 part) to be active on production but not in development as I don't have that data and want to test the ui using the data i have.


Solution

  • You can try this:

    if Rails.env.production?
      # define your scope
    end
    

    or, if you want to define different scopes on different environments, you can do something like this:

    default_scope do
      case Rails.env
      when 'production'
        # define production default scope
      when 'development'
        # define development default scope
      end
    end