HABTM - Error when saving: Method not found 'destroyed?' for Array - ruby-on-rails-4

I have two Models: Teacher and Department related by has_and_belongs_to_many.
When I try to save or update_attributes from the Teacher I get this error:
NoMethodError: undefined method 'destroyed?' for #<Array:0x007ff2af0204f0>
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/activerecord 4.0.2/lib/active_record/autosave_association.rb:380:in 'save_has_one_association'
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/activerecord-4.0.2/lib/active_record/autosave_association.rb:188:in 'block in add_autosave_association_callbacks'
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/activesupport-4.0.2/lib/active_support/callbacks.rb:383:in '_run__2528643575803035636__update__callbacks'
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/activesupport-4.0.2/lib/active_support/callbacks.rb:80:in 'run_callbacks'
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/activerecord-4.0.2/lib/active_record/callbacks.rb:310:in `update_record'
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/activerecord-4.0.2/lib/active_record/timestamp.rb:70:in `update_record'
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/activerecord-4.0.2/lib/active_record/persistence.rb:477:in `create_or_update'
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/activerecord-4.0.2/lib/active_record/callbacks.rb:302:in `block in create_or_update'
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/activesupport-4.0.2/lib/active_support/callbacks.rb:403:in `_run__2528643575803035636__save__callbacks'
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/activesupport-4.0.2/lib/active_support/callbacks.rb:80:in `run_callbacks'
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/activerecord-4.0.2/lib/active_record/callbacks.rb:302:in `create_or_update'
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/activerecord-4.0.2/lib/active_record/persistence.rb:106:in `save'
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/activerecord-4.0.2/lib/active_record/validations.rb:51:in `save'
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/activerecord-4.0.2/lib/active_record/attribute_methods/dirty.rb:32:in `save'
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/activerecord-4.0.2/lib/active_record/transactions.rb:270:in `block (2 levels) in save'
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/activerecord-4.0.2/lib/active_record/transactions.rb:326:in `block in with_transaction_returning_status'
... 4 levels...
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/activerecord-4.0.2/lib/active_record/transactions.rb:281:in `rollback_active_record_state!'
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/activerecord-4.0.2/lib/active_record/transactions.rb:269:in `save'
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/activerecord-4.0.2/lib/active_record/persistence.rb:230:in `block in update'
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/activerecord-4.0.2/lib/active_record/transactions.rb:326:in `block in with_transaction_returning_status'
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction'
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction'
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/activerecord-4.0.2/lib/active_record/transactions.rb:209:in `transaction'
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/activerecord-4.0.2/lib/active_record/transactions.rb:323:in `with_transaction_returning_status'
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/activerecord-4.0.2/lib/active_record/persistence.rb:228:in `update'
from (irb):45
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/railties-4.0.2/lib/rails/commands/console.rb:90:in `start'
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/railties-4.0.2/lib/rails/commands/console.rb:9:in `start'
from /Users/marcelomita/.rvm/gems/ruby-2.1.3/gems/railties-4.0.2/lib/rails/commands.rb:62:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
This error is preventing me to update my Teachers.
I don't know if this information is enogh, so if not ask me what you need. Thank you for your help and looking forward any answer.
EDIT
class Teacher < ActiveRecord::Base
#"validations are here"
has_and_belongs_to_many :department
end
class Department < ActiveRecord::Base
has_and_belongs_to_many :teacher
end

Related

undefined method `is_master=' for #<Product:0x0000000b8d5300>

Building off of this question/answer: NoMethodError - new since upgrading to Rails 4
Here is the relevant part of /models/product.rb
class Product < ActiveRecord::Base
delegate_attributes :is_master, :to => :master
has_one :master,
-> { where(["variants.is_master = ? AND variants.deleted_at IS NULL", true]) },
:class_name => 'Variant',
:autosave => true
accepts_nested_attributes_for :master, allow_destroy: false
And here is /models/variant.rb:
class Variant < ActiveRecord::Base
belongs_to :product
scope :master, -> { where(["variants.is_master = ? AND variants.deleted_at IS NULL", true]) }
Currently I get this error:
NoMethodError: undefined method `is_master=' for #<Product:0x0000000d63b980>
This didn't used to be a problem, prior to upgrading to Rails 4, because delegate_attributes should be handling it. The gem delegate_attributes is deprecated, but the methods have been moved into active_tools, which I have installed. But clearly something is still broken, so I have to work around it.
I solved a similar problem with price by:
def price=(amount)
master.price = amount
end
But when I try to do the same with is_master:
def is_master=(bool)
master.is_master = bool
end
I get the error that stack level too deep. Which I can kind of see why, if master.is_master is calling the method is_master over and over, but I wonder why this wasn't an issue with price.
This is where is_master is called, in /models/product.rb, but it's not inside Class Products.
module ProductConcerns
module Callbacks
extend ActiveSupport::Concern
included do
before_create :set_master_variant_defaults
end
def set_master_variant_defaults
self.is_master = true
end
end
end
Stack trace:
undefined method `is_master=' for #<Product:0x0000000c3bb378>
/pwd/vendor/ruby/2.1.0/gems/activemodel-4.2.10/lib/active_model/attribute_methods.rb:433:in `method_missing'
/pwd/app/models/product.rb:874:in `set_master_variant_defaults'
/pwd/vendor/ruby/2.1.0/gems/activesupport-4.2.10/lib/active_support/callbacks.rb:432:in `block in make_lambda'
/pwd/vendor/ruby/2.1.0/gems/activesupport-4.2.10/lib/active_support/callbacks.rb:164:in `call'
/pwd/vendor/ruby/2.1.0/gems/activesupport-4.2.10/lib/active_support/callbacks.rb:164:in `block in halting'
/pwd/vendor/ruby/2.1.0/gems/activesupport-4.2.10/lib/active_support/callbacks.rb:504:in `call'
/pwd/vendor/ruby/2.1.0/gems/activesupport-4.2.10/lib/active_support/callbacks.rb:504:in `block in call'
/pwd/vendor/ruby/2.1.0/gems/activesupport-4.2.10/lib/active_support/callbacks.rb:504:in `each'
/pwd/vendor/ruby/2.1.0/gems/activesupport-4.2.10/lib/active_support/callbacks.rb:504:in `call'
/pwd/vendor/ruby/2.1.0/gems/activesupport-4.2.10/lib/active_support/callbacks.rb:92:in `__run_callbacks__'
/pwd/vendor/ruby/2.1.0/gems/activesupport-4.2.10/lib/active_support/callbacks.rb:778:in `_run_create_callbacks'
/pwd/vendor/ruby/2.1.0/gems/activerecord-4.2.10/lib/active_record/callbacks.rb:306:in `_create_record'
/pwd/vendor/ruby/2.1.0/gems/activerecord-4.2.10/lib/active_record/timestamp.rb:57:in `_create_record'
/pwd/vendor/ruby/2.1.0/gems/activerecord-4.2.10/lib/active_record/persistence.rb:504:in `create_or_update'
/pwd/vendor/ruby/2.1.0/gems/activerecord-4.2.10/lib/active_record/callbacks.rb:302:in `block in create_or_update'
/pwd/vendor/ruby/2.1.0/gems/activesupport-4.2.10/lib/active_support/callbacks.rb:117:in `call'
/pwd/vendor/ruby/2.1.0/gems/activesupport-4.2.10/lib/active_support/callbacks.rb:117:in `call'
/pwd/vendor/ruby/2.1.0/gems/activesupport-4.2.10/lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
/pwd/vendor/ruby/2.1.0/gems/activesupport-4.2.10/lib/active_support/callbacks.rb:505:in `call'
/pwd/vendor/ruby/2.1.0/gems/activesupport-4.2.10/lib/active_support/callbacks.rb:505:in `call'
/pwd/vendor/ruby/2.1.0/gems/activesupport-4.2.10/lib/active_support/callbacks.rb:92:in `__run_callbacks__'
/pwd/vendor/ruby/2.1.0/gems/activesupport-4.2.10/lib/active_support/callbacks.rb:778:in `_run_save_callbacks'
/pwd/vendor/ruby/2.1.0/gems/activerecord-4.2.10/lib/active_record/callbacks.rb:302:in `create_or_update'
/pwd/vendor/ruby/2.1.0/gems/activerecord-4.2.10/lib/active_record/persistence.rb:142:in `save!'
/pwd/vendor/ruby/2.1.0/gems/activerecord-4.2.10/lib/active_record/validations.rb:43:in `save!'
/pwd/vendor/ruby/2.1.0/gems/activerecord-4.2.10/lib/active_record/attribute_methods/dirty.rb:29:in `save!'
/pwd/vendor/ruby/2.1.0/gems/activerecord-4.2.10/lib/active_record/transactions.rb:291:in `block in save!'
/pwd/vendor/ruby/2.1.0/gems/activerecord-4.2.10/lib/active_record/transactions.rb:351:in `block in with_transaction_returning_status'
/pwd/vendor/ruby/2.1.0/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `transaction'
/pwd/vendor/ruby/2.1.0/gems/activerecord-4.2.10/lib/active_record/transactions.rb:220:in `transaction'
/pwd/vendor/ruby/2.1.0/gems/activerecord-4.2.10/lib/active_record/transactions.rb:348:in `with_transaction_returning_status'
/pwd/vendor/ruby/2.1.0/gems/activerecord-4.2.10/lib/active_record/transactions.rb:291:in `save!'
/pwd/vendor/ruby/2.1.0/gems/state_machine-1.2.0/lib/state_machine/integrations/active_record.rb:487:in `block in save!'
/pwd/vendor/ruby/2.1.0/gems/state_machine-1.2.0/lib/state_machine/integrations/active_record.rb:502:in `block (2 levels) in around_save'
/pwd/vendor/ruby/2.1.0/gems/state_machine-1.2.0/lib/state_machine/transition_collection.rb:150:in `block in run_actions'
/pwd/vendor/ruby/2.1.0/gems/state_machine-1.2.0/lib/state_machine/transition_collection.rb:170:in `catch_exceptions'
/pwd/vendor/ruby/2.1.0/gems/state_machine-1.2.0/lib/state_machine/transition_collection.rb:148:in `run_actions'
/pwd/vendor/ruby/2.1.0/gems/state_machine-1.2.0/lib/state_machine/transition_collection.rb:133:in `run_callbacks'
/pwd/vendor/ruby/2.1.0/gems/state_machine-1.2.0/lib/state_machine/transition_collection.rb:212:in `run_callbacks'
/pwd/vendor/ruby/2.1.0/gems/state_machine-1.2.0/lib/state_machine/transition_collection.rb:63:in `block (2 levels) in perform'
/pwd/vendor/ruby/2.1.0/gems/state_machine-1.2.0/lib/state_machine/transition_collection.rb:63:in `catch'
/pwd/vendor/ruby/2.1.0/gems/state_machine-1.2.0/lib/state_machine/transition_collection.rb:63:in `block in perform'
/pwd/vendor/ruby/2.1.0/gems/state_machine-1.2.0/lib/state_machine/transition_collection.rb:186:in `within_transaction'
/pwd/vendor/ruby/2.1.0/gems/state_machine-1.2.0/lib/state_machine/transition_collection.rb:62:in `perform'
/pwd/vendor/ruby/2.1.0/gems/state_machine-1.2.0/lib/state_machine/integrations/active_record.rb:502:in `block in around_save'
/pwd/vendor/ruby/2.1.0/gems/state_machine-1.2.0/lib/state_machine/integrations/active_record.rb:530:in `block in transaction'
/pwd/vendor/ruby/2.1.0/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `transaction'
/pwd/vendor/ruby/2.1.0/gems/activerecord-4.2.10/lib/active_record/transactions.rb:220:in `transaction'
/pwd/vendor/ruby/2.1.0/gems/state_machine-1.2.0/lib/state_machine/integrations/active_record.rb:529:in `transaction'
/pwd/vendor/ruby/2.1.0/gems/state_machine-1.2.0/lib/state_machine/integrations/active_record.rb:501:in `around_save'
/pwd/vendor/ruby/2.1.0/gems/state_machine-1.2.0/lib/state_machine/integrations/active_record.rb:487:in `save!'
/pwd/vendor/ruby/2.1.0/gems/protected_attributes-1.1.4/lib/active_record/mass_assignment_security/validations.rb:17:in `create!'
/pwd/db/seeds.rb:112:in `block in create_merchant_with_listed_product'
/pwd/db/seeds.rb:110:in `times'
/pwd/db/seeds.rb:110:in `create_merchant_with_listed_product'
/pwd/db/seeds.rb:201:in `block in <top (required)>'
/pwd/vendor/ruby/2.1.0/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/pwd/vendor/ruby/2.1.0/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
/pwd/vendor/ruby/2.1.0/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/pwd/vendor/ruby/2.1.0/gems/activerecord-4.2.10/lib/active_record/transactions.rb:220:in `transaction'
/pwd/db/seeds.rb:8:in `<top (required)>'
/pwd/vendor/ruby/2.1.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:268:in `load'
/pwd/vendor/ruby/2.1.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:268:in `block in load'
/pwd/vendor/ruby/2.1.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:240:in `load_dependency'
/pwd/vendor/ruby/2.1.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:268:in `load'
/pwd/vendor/ruby/2.1.0/gems/railties-4.2.10/lib/rails/engine.rb:547:in `load_seed'
/pwd/vendor/ruby/2.1.0/gems/activerecord-4.2.10/lib/active_record/tasks/database_tasks.rb:253:in `load_seed'
/pwd/vendor/ruby/2.1.0/gems/activerecord-4.2.10/lib/active_record/railties/databases.rake:173:in `block (2 levels) in <top (required)>'
/pwd/vendor/ruby/2.1.0/gems/activerecord-4.2.10/lib/active_record/railties/databases.rake:132:in `block (2 levels) in <top (required)>'

`<top (required)>': uninitialized constant ActiveModelSerializers (NameError)

I am getting this error while running rails server as well as rake db:migrate, and I am using 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>'
you can explicitly write gem "active_model_serializers", require: true at Gemfile instead of requiring it at config/application.rb
OR
try to add below gems in Gemfile
gem "rails", "~> 5.0.0"
gem "rack-cors"
gem "active_model_serializers", "~> 0.10.0"

Rails giving undefined method `workers' for main:Object (NoMethodError)

I am trying to setup puma on heroku for a rails app. I'm following Heroku's guide on how to do it, but the config file they give doesn't seem to work, and I can't figure out why. When I don't use any config file, it runs fine, but I want to be able to specify the number of workers and threads it uses.
When I try to run the server, I get the following error:
C:/Users/Ephraim/Documents/lis/rails_app/config/initializers/puma.rb:1:in `<top (required)>': undefined method `workers' for main:Object (NoMethodError)
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `block in load'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/engine.rb:652:in `block in load_config_initializer'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/notifications.rb:166:in `instrument'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/engine.rb:651:in `load_config_initializer'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/engine.rb:616:in `block (2 levels) in <class:Engine>'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/engine.rb:615:in `each'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/engine.rb:615:in `block in <class:Engine>'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `instance_exec'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `run'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/initializable.rb:55:in `block in run_initializers'
from C:/Ruby21-x64/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
from C:/Ruby21-x64/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
from C:/Ruby21-x64/lib/ruby/2.1.0/tsort.rb:418:in `block (2 levels) in each_strongly_connected_component_from'
from C:/Ruby21-x64/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
from C:/Ruby21-x64/lib/ruby/2.1.0/tsort.rb:417:in `block in each_strongly_connected_component_from'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/initializable.rb:44:in `each'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/initializable.rb:44:in `tsort_each_child'
from C:/Ruby21-x64/lib/ruby/2.1.0/tsort.rb:411:in `call'
from C:/Ruby21-x64/lib/ruby/2.1.0/tsort.rb:411:in `each_strongly_connected_component_from'
from C:/Ruby21-x64/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
from C:/Ruby21-x64/lib/ruby/2.1.0/tsort.rb:345:in `each'
from C:/Ruby21-x64/lib/ruby/2.1.0/tsort.rb:345:in `call'
from C:/Ruby21-x64/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
from C:/Ruby21-x64/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
from C:/Ruby21-x64/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/initializable.rb:54:in `run_initializers'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/application.rb:352:in `initialize!'
from C:/Users/Ephraim/Documents/lis/rails_app/config/environment.rb:5:in `<top (required)>'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `block in require'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
from C:/Users/Ephraim/Documents/lis/rails_app/config.ru:3:in `block in <main>'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize'
from C:/Users/Ephraim/Documents/lis/rails_app/config.ru:in `new'
from C:/Users/Ephraim/Documents/lis/rails_app/config.ru:in `<main>'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `eval'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `new_from_string'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/builder.rb:40:in `parse_file'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/server.rb:299:in `build_app_and_options_from_config'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/server.rb:208:in `app'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/server.rb:61:in `app'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/server.rb:336:in `wrapped_app'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/server.rb:139:in `log_to_stdout'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/server.rb:78:in `start'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:80:in `block in server'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in `tap'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in `server'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
from C:/Users/Ephraim/Documents/lis/rails_app/bin/rails:8:in `require'
from C:/Users/Ephraim/Documents/lis/rails_app/bin/rails:8:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'
Here is the puma.rb initializer I'm using:
workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['MAX_THREADS'] || 5)
threads threads_count, threads_count
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
on_worker_boot do
# Worker specific setup for Rails 4.1+
# See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
ActiveRecord::Base.establish_connection
end
What would cause this to happen? And how can I fix it?
Referencing an answer from here: puma initializer does not work with rails 4.2
Put the puma.rb file in config/ not config/initializers/
you need to use foreman https://github.com/ddollar/foreman to run the Procfile. That is how heroku will spool up the app. once installed foreman start should do the trick. this just fooled me for a bit and I ran across your question.

sidekiq mongoid 4 not working

I am working with rails4 monogid and sidekiq , I am unable to start(exec) sidekiq with the following command
bundle exec sidekiq
following is the stack trace
wrong number of arguments (0 for 1)
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/gems/actionview-4.1.4/lib/action_view/helpers/debug_helper.rb:29:in `debug'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/gems/sprockets-rails-2.2.2/lib/sprockets/railtie.rb:114:in `block (2 levels) in <class:Railtie>'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/gems/activesupport-4.1.4/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/gems/activesupport-4.1.4/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/gems/activesupport-4.1.4/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/gems/activesupport-4.1.4/lib/active_support/lazy_load_hooks.rb:27:in `each'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/gems/activesupport-4.1.4/lib/active_support/lazy_load_hooks.rb:27:in `on_load'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/gems/sprockets-rails-2.2.2/lib/sprockets/railtie.rb:110:in `block in <class:Railtie>'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/gems/activesupport-4.1.4/lib/active_support/lazy_load_hooks.rb:36:in `call'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/gems/activesupport-4.1.4/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/gems/activesupport-4.1.4/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/gems/activesupport-4.1.4/lib/active_support/lazy_load_hooks.rb:44:in `each'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/gems/activesupport-4.1.4/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/gems/railties-4.1.4/lib/rails/application/finisher.rb:64:in `block in <module:Finisher>'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/gems/railties-4.1.4/lib/rails/initializable.rb:30:in `instance_exec'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/gems/railties-4.1.4/lib/rails/initializable.rb:30:in `run'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/gems/railties-4.1.4/lib/rails/initializable.rb:55:in `block in run_initializers'
/home/ratna/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
/home/ratna/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
/home/ratna/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
/home/ratna/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
/home/ratna/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:345:in `each'
/home/ratna/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:345:in `call'
/home/ratna/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
/home/ratna/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
/home/ratna/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/gems/railties-4.1.4/lib/rails/initializable.rb:54:in `run_initializers'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/gems/railties-4.1.4/lib/rails/application.rb:300:in `initialize!'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/gems/railties-4.1.4/lib/rails/railtie.rb:194:in `public_send'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/gems/railties-4.1.4/lib/rails/railtie.rb:194:in `method_missing'
/home/ratna/ratna/Projects/Vrcommand/Dec/dec10/vrcommand/config/environment.rb:6:in `<top (required)>'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `block in require'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:232:in `load_dependency'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/gems/sidekiq-3.3.0/lib/sidekiq/cli.rb:236:in `boot_system'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/gems/sidekiq-3.3.0/lib/sidekiq/cli.rb:50:in `run'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/gems/sidekiq-3.3.0/bin/sidekiq:8:in `<top (required)>'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/bin/sidekiq:23:in `load'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/bin/sidekiq:23:in `<main>'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/bin/ruby_executable_hooks:15:in `eval'
/home/ratna/.rvm/gems/ruby-2.1.5#vrcommand/bin/ruby_executable_hooks:15:in `<main>'
I am not sure why I am getting this error , can anyone please help me .
Thanks in advance
I fixed it by downgrading the sidekiq version to 3.1.x , I am getting issues with 3.2.x

Getting error in rails after installing devise

I am getting this error after installing devise for users
C:3:in `rescue in execute_if_updated': Rails::Application::RoutesReloader#execut
e_if_updated delegated to updater.execute_if_updated, but updater is nil: #<Rail
s::Application::RoutesReloader:0x3900780 #paths=["C:/ror/wishlistize/config/rout
es.rb"], #route_sets=[#<ActionDispatch::Routing::RouteSet:0x393a140>]> (RuntimeE
rror)
from C:131071:in `execute_if_updated'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/applic
ation/finisher.rb:69:in `block in <module:Finisher>'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/initia
lizable.rb:30:in `instance_exec'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/initia
lizable.rb:30:in `run'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/initia
lizable.rb:55:in `block in run_initializers'
from C:/Ruby200/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
from C:/Ruby200/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each
_strongly_connected_component'
from C:/Ruby200/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_
component_from'
from C:/Ruby200/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_c
onnected_component'
from C:/Ruby200/lib/ruby/2.0.0/tsort.rb:180:in `each'
from C:/Ruby200/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_
component'
from C:/Ruby200/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/initia
lizable.rb:54:in `run_initializers'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/applic
ation.rb:215:in `initialize!'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/railti
e/configurable.rb:30:in `method_missing'
from C:/ror/wishlistize/config/environment.rb:5:in `<top (required)>'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_
support/dependencies.rb:228:in `require'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_
support/dependencies.rb:228:in `block in require'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_
support/dependencies.rb:213:in `load_dependency'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_
support/dependencies.rb:228:in `require'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/applic
ation.rb:189:in `require_environment!'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/comman
ds.rb:45:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
I am not sure if its because of devise
here's my routes file
Wishlistize::Application.routes.draw do
devise_for :users
end
and environment.rb
# Load the Rails application.
require File.expand_path('../application', __FILE__)
# Initialize the Rails application.
Wishlistize::Application.initialize!
I get this when i run rake db:migrate
User model:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
Okay I figure this out. I did not actually run rails g devise:install but directly rails g devise:user according to the tutorial that I had read. It seems that was causing the problem. I installed the edge version and it became clear.