Rails 3 namespacing requires model to be defined twice?

Posted by RSG on Stack Overflow See other posts from Stack Overflow or by RSG
Published on 2011-02-11T07:14:05Z Indexed on 2011/02/11 7:25 UTC
Read the original article Hit count: 169

I'm pulling my hair out trying to understand namespacing in Rails 3. I've tried following a few different tutorials, and the only way I can get my models to work is if I define my model in both the base directory and my namespace directory.

If I only define the model in the namespace directory it expects it to define both Model and Namespace::Model, as below:

LoadError (Expected .../app/models/plugins/chat.rb to define Chat):

or

LoadError (Expected .../app/models/plugins/chat.rb to define Plugins::Chat):

I'm sure I'm missing something obvious, but I could really use a pointer in the right direction. Here are the relevant excerpts.

/models/plugins/chat.rb

class Plugins::Chat
  include ActiveModel::Validations
  include ActiveModel::Conversion
  extend ActiveModel::Naming
...
end

/controllers/plugins/chats_controller.rb

class Plugins::ChatsController < Plugins::ApplicationController
load_and_authorize_resource
...  
end

/config/routes.rb

namespace :plugins do 
  resources :chats
end

/config/application.rb

config.autoload_paths += Dir["#{config.root}/app/models/**/"]

© Stack Overflow or respective owner

Related posts about ruby-on-rails-3

Related posts about namespaces