What is the proper way to use namespaces and reference models inheriting from other (mongoid/rails)? -


i have model handlingscenario inherits scenario. this:

## models/scenario.rb class scenario   include mongoid::document end  ## models/scenarios/handling_scenario.rb class scenarios::handlingscenario < scenario   include mongoid::document   belongs_to :user, :inverse_of => :handling_scenarios  # in `user` model, reference `has_many :handling_scenarios` end 

but when try access handlingscenario class, trouble:

➜  rails c loading development environment (rails 3.2.12) 2.0.0-p247 :001 > user.first.handling_scenarios loaderror: expected /users/christoffer/projects/my_project/app/models/scenarios/handling_scenario.rb define handlingscenario 

also, when try visit through browser error:

started "/scenarios/handling_scenarios" 127.0.0.1 @ 2013-10-06 19:41:29 +0200 processing scenarios::handlingscenarioscontroller#index html   moped: 127.0.0.1:27017 query        database=my_project_development collection=users selector={"$query"=>{"_id"=>"518f599683c336fb87000003"}, "$orderby"=>{:_id=>1}} flags=[:slave_ok] limit=-1 skip=0 batch_size=nil fields=nil (0.3998ms) completed 500 internal server error in 7ms  nameerror - uninitialized constant handlingscenario: 

the controller action is:

## controllers/scenarios/handling_scenarios_controller.rb class scenarios::handlingscenarioscontroller < scenarioscontroller   def index     @handling_scenarios = current_user.handling_scenarios   end end 

and routes are:

## config/routes.rb namespace :scenarios   resources :handling_scenarios     member       ...     end   end end 

use class_name option relation 'has_many :handling_scenarios' rails knows model handling_scenario in file scenarios/handling_scenario.rb:

## models/user.rb class user    include mongoid::document    has_many :handling_scenarios, class_name: "scenarios::handlingscenario" end 

see: http://mongoid.org/en/mongoid/docs/relations.html

besides dont need include mongoid::document in scenarios::handlingscenario since inherited scenario.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -