Default scope for production but not in development

209 views Asked by At

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.

1

There are 1 answers

5
Marek Lipka On BEST ANSWER

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