Rails引擎:未初始化的常量用户

时间:2016-04-22 07:18:24

标签: ruby-on-rails ruby ruby-on-rails-3

关于堆栈溢出的第一个问题! 我正在尝试将rails应用程序转换为引擎,以便我可以在我自己的Rails应用程序中使用它。

我已将所有内容转换为引擎模块等(我仍然在我的引擎目录中并且尚未在我的rails应用程序中开始实现它)但是当我在根目录中运行rake db:migrate时出现错误:

rake aborted!
NameError: uninitialized constant User
/Users/matthijskolkman/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0    /gems/activesupport-4.2.6/lib/active_support/inflector/methods.rb:261:in `const_get'
/Users/matthijskolkman/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0    /gems/activesupport-4.2.6/lib/active_support/inflector/methods.rb:261:in `block in constantize'
/Users/matthijskolkman/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-4.2.6/lib/active_support/inflector/methods.rb:259:in `each'
/Users/matthijskolkman/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-4.2.6/lib/active_support/inflector/methods.rb:259:in `inject'
/Users/matthijskolkman/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-4.2.6/lib/active_support/inflector/methods.rb:259:in `constantize'
/Users/matthijskolkman/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/devise-3.5.6/lib/devise.rb:292:in `get'
/Users/matthijskolkman/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/devise-3.5.6/lib/devise/mapping.rb:81:in `to'
/Users/matthijskolkman/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/devise-3.5.6/lib/devise/mapping.rb:76:in `modules'
/Users/matthijskolkman/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/devise-3.5.6/lib/devise/mapping.rb:93:in `routes'
/Users/matthijskolkman/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/devise-3.5.6/lib/devise/mapping.rb:160:in `default_used_route'
/Users/matthijskolkman/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/devise-3.5.6/lib/devise/mapping.rb:70:in `initialize'
/Users/matthijskolkman/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/devise-3.5.6/lib/devise.rb:326:in `new'
/Users/matthijskolkman/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/devise-3.5.6/lib/devise.rb:326:in `add_mapping'
/Users/matthijskolkman/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/devise-3.5.6/lib/devise/rails/routes.rb:238:in `block in devise_for'
/Users/matthijskolkman/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/devise-3.5.6/lib/devise/rails/routes.rb:237:in `each'
/Users/matthijskolkman/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/devise-3.5.6/lib/devise/rails/routes.rb:237:in `devise_for'
/Users/matthijskolkman/Projects/customer_service_gem/brimir/config/routes.rb:2:in `block in <top (required)>'

我认为这与路由有关,但不确定。 这是我的路线:

Brimir::Engine.routes.draw do
  devise_for :users, controllers: { omniauth_callbacks: 'omniauth' }

  resources :users do
    get :tickets, to: 'tickets#index'
  end

  namespace :tickets do
    resource :deleted, only: :destroy, controller: :deleted
    resource :selected, only: :update, controller: :selected
  end

  resources :tickets, except: [:destroy, :edit] do
    resource :lock, only: [:destroy, :create], module: :tickets
  end

  resources :labelings, only: [:destroy, :create]

  resources :rules

  resources :labels, only: [:destroy, :update, :index, :edit]

  resources :replies, only: [:create, :new, :update, :show]

  get '/attachments/:id/:format' => 'attachments#show'
  resources :attachments, only: [:index, :new]

  resources :email_addresses

  resource :settings, only: [:edit, :update]

  root to: 'tickets#index'

  namespace :api do
    namespace :v1 do
      resources :tickets, only: [ :index, :show, :create ]
      resources :sessions, only: [ :create ]
      resources :users, param: :email, only: [ :create, :show ] do
        resources :tickets, only: [ :index ]
      end
    end
  end
end

用户控制器(app / controllers / brimir / users_controller.rb):

module Brimir
  class UsersController < ApplicationController
    include UsersStrongParams
    load_and_authorize_resource :user

    def edit
      @user = User.find(params[:id])
    end

    def update
....

模型(app / models / brimir / user.rb)

module Brimir
  class User < ActiveRecord::Base
    devise Rails.application.config.devise_authentication_strategy, :recoverable,
      :rememberable, :trackable, :validatable,:omniauthable,
      omniauth_providers: [:google_oauth2]

    has_many :tickets, dependent: :destroy
    has_many :replies, dependent: :destroy
    has_many :labelings, as: :labelable, dependent: :destroy
    has_many :labels, through: :labelings
    has_many :assigned_tickets, class_name: 'Ticket',
        foreign_key: 'assignee_id', dependent: :nullify
    has_many :notifications

    # identities for omniauth
    has_many :identities

    after_initialize :default_localization
    before_validation :generate_password

    # All ldap users are agents by default, remove/comment this method if this
    # is not the intended behavior.
    def ldap_before_save
      self.agent = true
    ....

提前致谢!

0 个答案:

没有答案