开发者

Access non-namespaced model from inside namespaced controller

开发者 https://www.devze.com 2023-03-18 01:19 出处:网络
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 fo

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消