0

Is it possible to load a resource using a subdomain in CanCan?

The load_resource and load_and_authorize_resource methods are an alias to this:

def load
    @foo = Resource.find(params[:id])
end

In my case, I need to load the resource based on a subdomain. Any idea how to achieve this?

Mohamad
  • 34,731
  • 32
  • 140
  • 219

1 Answers1

2

You can overwrite the load_resource to use the subdomain instead and than just call authorize_resource on it

Not sure how you code is structured, but something along this lines should work

class YourController < ApplicationController
  before_filter :find_by_subdomain
  load_and_authorize_resource

  private

  def find_by_subdomain
    @book = Model.find_by_subdomain(request.subdomain)
  end
end
Yuriy Goldshtrakh
  • 2,014
  • 1
  • 11
  • 7