`<top(required)=“”>':未初始化的常量ActiveModelSerializers(NameError)

时间:2017-05-22 10:38:15

标签: ruby-on-rails-4

运行rails server以及rake db:migrate时出现此错误,我正在使用rails-4.2.7

api/config/initializers/active_model_serializers.rb:1:in `<top (required)>': uninitialized constant ActiveModelSerializers (NameError)
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/railties-4.2.8/lib/rails/engine.rb:652:in `block in load_config_initializer'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/activesupport-4.2.8/lib/active_support/notifications.rb:166:in `instrument'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/railties-4.2.8/lib/rails/engine.rb:651:in `load_config_initializer'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/railties-4.2.8/lib/rails/engine.rb:616:in `block (2 levels) in <class:Engine>'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/railties-4.2.8/lib/rails/engine.rb:615:in `each'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/railties-4.2.8/lib/rails/engine.rb:615:in `block in <class:Engine>'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/railties-4.2.8/lib/rails/initializable.rb:30:in `instance_exec'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/railties-4.2.8/lib/rails/initializable.rb:30:in `run'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/railties-4.2.8/lib/rails/initializable.rb:55:in `block in run_initializers'
from /home/ganeshmohan/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each'
from /home/ganeshmohan/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
from /home/ganeshmohan/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/tsort.rb:420:in `block (2 levels) in each_strongly_connected_component_from'
from /home/ganeshmohan/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from'
from /home/ganeshmohan/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/tsort.rb:419:in `block in each_strongly_connected_component_from'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/railties-4.2.8/lib/rails/initializable.rb:44:in `each'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/railties-4.2.8/lib/rails/initializable.rb:44:in `tsort_each_child'
from /home/ganeshmohan/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/tsort.rb:413:in `call'
from /home/ganeshmohan/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/tsort.rb:413:in `each_strongly_connected_component_from'
from /home/ganeshmohan/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component'
from /home/ganeshmohan/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/tsort.rb:345:in `each'
from /home/ganeshmohan/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/tsort.rb:345:in `call'
from /home/ganeshmohan/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component'
from /home/ganeshmohan/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each'
from /home/ganeshmohan/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/railties-4.2.8/lib/rails/initializable.rb:54:in `run_initializers'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/railties-4.2.8/lib/rails/application.rb:352:in `initialize!'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/railties-4.2.8/lib/rails/railtie.rb:194:in `public_send'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/railties-4.2.8/lib/rails/railtie.rb:194:in `method_missing'
from /home/ganeshmohan/work_space/Givecorps-site/config/environment.rb:19:in `<top (required)>'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/skylight-1.2.2/lib/skylight/probes.rb:81:in `require'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/skylight-1.2.2/lib/skylight/probes.rb:81:in `require'
from /home/ganeshmohan/work_space/Givecorps-site/config.ru:3:in `block in <main>'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/rack-1.6.8/lib/rack/builder.rb:55:in `instance_eval'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/rack-1.6.8/lib/rack/builder.rb:55:in `initialize'
from /home/ganeshmohan/work_space/Givecorps-site/config.ru:in `new'
from /home/ganeshmohan/work_space/Givecorps-site/config.ru:in `<main>'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/rack-1.6.8/lib/rack/builder.rb:49:in `eval'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/rack-1.6.8/lib/rack/builder.rb:49:in `new_from_string'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/rack-1.6.8/lib/rack/builder.rb:40:in `parse_file'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/rack-1.6.8/lib/rack/server.rb:300:in `build_app_and_options_from_config'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/rack-1.6.8/lib/rack/server.rb:209:in `app'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/railties-4.2.8/lib/rails/commands/server.rb:61:in `app'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/rack-1.6.8/lib/rack/server.rb:337:in `wrapped_app'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/railties-4.2.8/lib/rails/commands/server.rb:139:in `log_to_stdout'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/railties-4.2.8/lib/rails/commands/server.rb:78:in `start'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/railties-4.2.8/lib/rails/commands/commands_tasks.rb:80:in `block in server'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/railties-4.2.8/lib/rails/commands/commands_tasks.rb:75:in `tap'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/railties-4.2.8/lib/rails/commands/commands_tasks.rb:75:in `server'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/railties-4.2.8/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/railties-4.2.8/lib/rails/commands.rb:17:in `<top (required)>'
from /home/ganeshmohan/work_space/Givecorps-site/bin/rails:10:in `require'
from /home/ganeshmohan/work_space/Givecorps-site/bin/rails:10:in `<top (required)>'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/spring-2.0.1/lib/spring/client/rails.rb:28:in `load'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/spring-2.0.1/lib/spring/client/rails.rb:28:in `call'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/spring-2.0.1/lib/spring/client/command.rb:7:in `call'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/spring-2.0.1/lib/spring/client.rb:30:in `run'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/spring-2.0.1/bin/spring:49:in `<top (required)>'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/spring-2.0.1/lib/spring/binstub.rb:31:in `load'
from /home/ganeshmohan/.rvm/gems/ruby-2.2.5/gems/spring-2.0.1/lib/spring/binstub.rb:31:in `<top (required)>'
from /home/ganeshmohan/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:69:in `require'
from /home/ganeshmohan/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:69:in `require'
from /home/ganeshmohan/work_space/Givecorps-site/bin/spring:16:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'

1 个答案:

答案 0 :(得分:0)

您可以在# import libraries from keras.models import Sequential from keras.layers import Conv2D from keras.layers import MaxPooling2D from keras.layers import Flatten from keras.layers import Dense # import dataset from keras.preprocessing.image import ImageDataGenerator train_datagen = ImageDataGenerator() test_datagen = ImageDataGenerator() training_set = train_datagen.flow_from_directory('data/spectrogramme/ensemble_de_formation', target_size = (64, 64), batch_size = 128, class_mode = 'binary') test_set = test_datagen.flow_from_directory('data/spectrogramme/ensemble_de_test', target_size = (64, 64), batch_size = 128, class_mode = 'binary') # initializing reseau = Sequential() # 1. convolution reseau.add(Conv2D(32, (3, 3), input_shape = (64, 64, 3), activation = 'relu')) reseau.add(MaxPooling2D(pool_size = (2, 2))) reseau.add(Conv2D(32, (3, 3), activation = 'relu')) reseau.add(MaxPooling2D(pool_size = (2, 2))) reseau.add(Conv2D(64, (3, 3), activation = 'relu')) reseau.add(MaxPooling2D(pool_size = (2, 2))) reseau.add(Conv2D(64, (3, 3), activation = 'relu')) reseau.add(MaxPooling2D(pool_size = (2, 2))) # 2. flatenning reseau.add(Flatten()) # 3. fully connected from keras.layers import Dropout reseau.add(Dense(units = 64, activation = 'relu')) reseau.add(Dropout(0.1)) reseau.add(Dense(units = 128, activation = 'relu')) reseau.add(Dropout(0.05)) reseau.add(Dense(units = 256, activation = 'relu')) reseau.add(Dropout(0.03)) reseau.add(Dense(units = 1, activation = 'sigmoid')) # 4. compile reseau.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy']) # 5. fit reseau.fit_generator(training_set, steps_per_epoch = 8000, epochs = 1, validation_data = test_set, validation_steps = 2000) 明确写下gem "active_model_serializers", require: true,而不是Gemfile

OR

尝试在config/application.rb

中添加以下宝石
Gemfile