2015-01-21 2 views
3

을 나는 Configurable 모델이 : 내 pages_controllerConfigurable를 참조하면레일 구성 모델 ActiveSupport와 충돌 :: 구성 : 구성 : 클래스

# /models/configuration.rb 
class Configuration < ActiveRecord::Base 
end 

를, 잘 작동 :

class PagesController < ApplicationController 
    def search 
    @description = Configuration.find_by_name('description') || nil 
    end 
end 

그러나 내 application_controller.rb에서 참조 할 때

class ApplicationController < ActionController::Base 
    def get_menu 
     @menu = Configuration.where(name: 'menu') || nil 
    end 
end 

오류 undefined method 'where' for ActiveSupport::Configurable::Configuration:Class가 표시됩니다. Configuration 모델과 ActiveSupport::Configurable::Configuration:Class이 이와 같이 충돌하거나 내 모델 Configuration을 직접 참조하지 못하게하려면 어떻게해야하나요?

미리 감사드립니다.

답변

5

당신은

::Configuration.where(name: 'menu') 

공지 사항 클래스 이름 앞에 :: 접두사해야합니다. 그들은 ActiveSupport 네임 스페이스가 아닌 메인 네임 스페이스에서 Configuration 클래스를 사용하도록 통역사를 강요합니다.

+1

저에게 도움이되었으므로 타이머가 끝나면 올바르게 표시해 드리겠습니다. '::'앞에 무엇인가 암시 된 것이 궁금합니다. –