Access non-namespaced model from inside namespaced controller
I have a namespaced model "quiz" under Student, and I need to access a model without a namespace of the same name. I can't do Quiz.all because it's in the namespace, how do I get the Quiz stuff for the model without the namespace?
My model is class Quiz < ActiveRecord::Base
The model is in app/models/quiz.rb
My controller is class Stude开发者_StackOverflow社区nt::QuizzesController < ApplicationController
The controller is in app/controllers/student/quizzes_controller.rb
I also have another model that's a namespaced version of quiz. class Student::Quiz < ActiveRecord::Base
, and when I generated the model it made a student.rb model in the app/models directory that has this in it.
module Student
def self.table_name_prefix
'student_'
end
end
You can use ::Quiz to explicitly refer to the toplevel Quiz constant.
精彩评论