2

I have the following routes:

resources :boilerplates
resources :projects do
  resources :boilerplates
end

The Boilerplate model looks like this:

class Boilerplate < ActiveRecord::Base
  scope :originals, -> { where(prototype_id: nil) }
end

My controller looks like this:

class BoilerplatesController < InheritedResources::Base
  load_and_authorize_resource
  belongs_to :project, optional: true
end

When the URL /boilerplates is opened, I want to display all boilerplates with the originals scope.

When the URL /projects/123/boilerplates is opened, I want the originals scope not to be active.

How can this be achieved?

Joshua Muheim
  • 12,617
  • 9
  • 76
  • 152

1 Answers1

1

I just found a way to do this myself. In BoilerplatesController:

protected

def collection
  if @project
    super
  else
    super.originals
  end
end
Joshua Muheim
  • 12,617
  • 9
  • 76
  • 152