How is it possible the class inheritance in namespaces using Ruby on Rails 3?

Posted by user502052 on Stack Overflow See other posts from Stack Overflow or by user502052
Published on 2011-01-11T14:50:27Z Indexed on 2011/01/11 14:53 UTC
Read the original article Hit count: 236

In my RoR3 application I have a namespace called NS1 so that I have this filesystem structure:

ROOT_RAILS/controllers/
ROOT_RAILS/controllers/application_controller.rb
ROOT_RAILS/controllers/ns/
ROOT_RAILS/controllers/ns/ns_controller.rb
ROOT_RAILS/controllers/ns/names_controller.rb
ROOT_RAILS/controllers/ns/surnames_controller.rb

I wuold like that 'ns_controller.rb' inherits from application controller, so in 'ns_controller.rb' file I have:

class Ns::NsController < ApplicationController
  ...
end

Is this the right approach? Anyway if I have this situation...

in 'application_controller.rb'

class ApplicationController < ActionController::Base
  @profile = Profile.find(1)
end

in 'ns_controller.rb'

class Ns::NsController < ApplicationController
  @name = @profile.name
  @surname = @profile.surname
end

... '@name' and '@surname' variables are not set. Why?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby