Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange Model class name lookups when using namespaces #72

Open
ejlangev opened this issue Jul 31, 2014 · 0 comments
Open

Strange Model class name lookups when using namespaces #72

ejlangev opened this issue Jul 31, 2014 · 0 comments

Comments

@ejlangev
Copy link
Contributor

The following case fails (assume that ApplicationRepresenter sets up the included modules for Roar and ApplicationController includes Roar::Rails::ControllerAdditions:

module Instruments
  class Trumpet < ActiveRecord::Base
  end

  class TrumpetRepresenter < ApplicationRepresenter
  end

  class TrumpetsController < ApplicationController
    def show
      trumpet = Trumpet.find(params[:id])
      respond_with trumpet
    end
  end
end

The error is: Uninitialized Constant Instruments::Instruments. Seems like a better method of selecting a representer would be the following:

Assume you have a controller namespaced as N1::N2::Controller and a representer namespaced as N1::ModelRepresenter:

Check for the following constants in order and if none is found then fail with Uninitialized constant: N1::ModelRepresenter

N1::N2::N1::ModelRepresenter
N1::N1::ModelRepresenter
N1::ModelRepresenter

This way if the model is not namespaced it takes on the controllers namespace by default but can still find an un-namespaced representer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant