My first question on stack overflow! I am trying to convert a rails app into an engine so that I can use it in my own Rails app.
I have converted everything to engine modules etc. (I'm still in my engine directory and haven't started implemented it yet in my rails app) but when I run rake db:migrate
in the root I get the error:
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)>'
I think it has to do with the routing, but not sure. Here are my routes:
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
And the user controller:
module Brimir
class UsersController < ApplicationController
include UsersStrongParams
load_and_authorize_resource :user
def edit
@user = User.find(params[:id])
end
def update
@user = User.find(params[:id])
# if no password was posted, remove from params
if params[:user][:password] == ''
params[:user].delete(:password)
params[:user].delete(:password_confirmation)
end
if current_user == @user
params[:user].delete(:agent) # prevent removing own agent permissions
end
if @user.update_attributes(user_params)
if current_user.agent? && current_user.labelings.count == 0
redirect_to users_url, notice: I18n.translate(:settings_saved)
else
redirect_to tickets_url, notice: I18n.translate(:settings_saved)
end
else
render action: 'edit'
end
end
def index
@users = User.ordered.paginate(page: params[:page])
@users = @users.search(params[:q])
@users = @users.by_agent(params[:agent] == '1') unless params[:agent].blank?
end
def new
@user = User.new
end
def create
@user = User.new(user_params)
if @user.save
redirect_to users_url, notice: I18n.translate(:user_added)
else
render 'new'
end
end
def destroy
@user = User.find(params[:id])
@user.destroy
redirect_to users_url, notice: I18n.translate(:user_removed)
end
end
end
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire