Jaijaz
Jaijaz

Reputation: 134

routing errors based on rail environment

I have subdomain routing setup like this

constraints :subdomain => 'my' do
  scope :module => 'my', :as => 'my' do
    scope :module => 'author', :as => 'author' do
      resources :modlette_author
    end
    resources :modlettes
    root :to => 'my#index'
  end
end

When I'm in a development environment, and in particular config.cache_classes = false the my_controller needs to sit in app/controllers and be defined like this:

class MyController < ApplicationController
  layout "my"
  before_filter :authenticate_user!

  def index

  end
end

However in production when config.cache_classes = true rails wants the my_controller to be in app/controllers/my and be defined like this:

class My::MyController < ApplicationController
  layout "my"
  before_filter :authenticate_user!

  def index

  end
end

Obviously it isn't practical to try and do both. Has anyone got any ideas on what I am doing wrong?

Upvotes: 0

Views: 72

Answers (2)

Jaijaz
Jaijaz

Reputation: 134

While what Alex wrote was 100% correct there was a lot more wrong than just what Alex wrote. I ended up re-writting a large chunk for routes, and re-organising all the controller paths and controller names. I in re-writting all this from scratch I used the following links:

Rails Guides

Railscasts REST API Versioning

Upvotes: 0

alex
alex

Reputation: 3742

Try to change scope :module => 'my', :as => 'my' do to namespace :my, path: nil do so it will work in development mode like in production.

Upvotes: 1

Related Questions