Cannot define multiple 'included' blocks for a Concern with sidekiq - ruby-on-rails

I am experiencing the below exception if I am running the sidekiq:
It can be seen that the date_at_relative_to_now class is required twice by some weird reason despite the fact that I am not using require nor require_relative in my application. I am relying exclusively to rails autoload feature.
Any ide or help is appreciated
→ sidekiq
loading...
loading...
Cannot define multiple 'included' blocks for a Concern
/Users/boti/.rvm/gems/ruby-2.2.0#checker/gems/activesupport-4.2.0/lib/active_support/concern.rb:126:in `included'
/Users/boti/Rails/checker/app/exhibits/concerns/date_at_relative_to_now.rb:6:in `<module:DateAtRelativeToNow>'
/Users/boti/Rails/checker/app/exhibits/concerns/date_at_relative_to_now.rb:3:in `<top (required)>'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:457:in `load'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:457:in `block in load_file'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:647:in `new_constants_in'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:456:in `load_file'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:354:in `require_or_load'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:317:in `depend_on'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:233:in `require_dependency'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/gems/railties-4.2.0/lib/rails/engine.rb:472:in `block (2 levels) in eager_load!'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/gems/railties-4.2.0/lib/rails/engine.rb:471:in `each'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/gems/railties-4.2.0/lib/rails/engine.rb:471:in `block in eager_load!'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/gems/railties-4.2.0/lib/rails/engine.rb:469:in `each'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/gems/railties-4.2.0/lib/rails/engine.rb:469:in `eager_load!'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/gems/railties-4.2.0/lib/rails/engine.rb:346:in `eager_load!'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/gems/railties-4.2.0/lib/rails/application/finisher.rb:56:in `each'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/gems/railties-4.2.0/lib/rails/application/finisher.rb:56:in `block in <module:Finisher>'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `instance_exec'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `run'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/gems/railties-4.2.0/lib/rails/initializable.rb:55:in `block in run_initializers'
/Users/boti/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each'
/Users/boti/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
/Users/boti/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from'
/Users/boti/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component'
/Users/boti/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:345:in `each'
/Users/boti/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:345:in `call'
/Users/boti/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component'
/Users/boti/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each'
/Users/boti/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/gems/railties-4.2.0/lib/rails/initializable.rb:54:in `run_initializers'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/gems/railties-4.2.0/lib/rails/application.rb:352:in `initialize!'
/Users/boti/Rails/checker/config/environment.rb:5:in `<top (required)>'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `block in require'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/gems/sidekiq-3.3.4/lib/sidekiq/cli.rb:241:in `boot_system'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/gems/sidekiq-3.3.4/lib/sidekiq/cli.rb:50:in `run'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/gems/sidekiq-3.3.4/bin/sidekiq:8:in `<top (required)>'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/bin/sidekiq:23:in `load'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/bin/sidekiq:23:in `<main>'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/bin/ruby_executable_hooks:15:in `eval'
/Users/boti/.rvm/gems/ruby-2.2.0#checker/bin/ruby_executable_hooks:15:in `<main>'
ruby-2.2.0#checker:boti:~/Rails/checker git:active_job_exercise
→
The code for date_at_relative_to_now.rb:
module DateAtRelativeToNow
puts 'loading...'
extend ActiveSupport::Concern
included do
include ActionView::Helpers::DateHelper
end
module ClassMethods
attr_reader :field
def applicable_to?(object, _context)
field = self.field
object.respond_to? field
end
def applicable_to(field)
#field = field
define_method field do
date = __getobj__.send self.__class__.field
if date.present?
"#{distance_of_time_in_words_to_now date} ago"
else
'Never'
end
end
end
end
end

Issue occuring as activesupport does not support include inside 'included' block.
Remove include ActionView::Helpers::DateHelper line from DateAtRelativeToNow and included it in module or class wherever you need.

Implemention of activesupport 'included' function:
def included(base = nil, &block)
if base.nil?
raise MultipleIncludedBlocks if instance_variable_defined?(:#_included_block)
#_included_block = block
else
super
end
end

Related

How can I load a custom validator which does not directly inherit from a Rails validator class in Rails 5?

I was writing some custom validators for a Rails 5 project I have been working on. For example:
class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
if value.present? && !/\A[^\p{Z}]+#[^\p{Z}]+\.[^\p{Z}]+\z/.match?(value)
record.errors.add(attribute, "must be an email")
end
end
end
This approach worked fine, but many of my custom validators were similarly checking for a regex match so I decided to create an abstract RegexValidator class:
class RegexValidator < ActiveModel::EachValidator
self.abstract_class = true
def regex
raise "Children of this class must implement the 'regex' method."
end
def message(record, attribute, value)
raise "Children of this class must implement the 'message(record, attribute, value)' method."
end
def validate_each(record, attribute, value)
if value.present? && !regex.match?(value)
record.errors.add(attribute, message(record, attribute, value))
end
end
end
So now EmailValidator is implemented like so:
class EmailValidator < RegexValidator
def regex
/\A[^\p{Z}]+#[^\p{Z}]+\.[^\p{Z}]+\z/
end
def message(record, attribute, value)
"must be an email"
end
end
However, since this change Rails 5 no longer autoloads my EmailValidator even though both RegexValidator and EmailValidator are placed in appropriately named files, regex_validator.rb and email_validator.rb, in the app/validators folder which was being autoloaded before (this makes this question different from a similar question). I suspect this is because EmailValidator no longer directly inherits from ActiveModel::EachValidator, but this should not matter.
For reference, the following error occurred when I tried to generate a migration file:
/var/lib/gems/2.5.0/gems/activemodel-5.2.2/lib/active_model/validations/validates.rb:121:in `rescue in block in validates': Unknown validator: 'EmailValidator' (ArgumentError)
from /var/lib/gems/2.5.0/gems/activemodel-5.2.2/lib/active_model/validations/validates.rb:118:in `block in validates'
from /var/lib/gems/2.5.0/gems/activemodel-5.2.2/lib/active_model/validations/validates.rb:114:in `each'
from /var/lib/gems/2.5.0/gems/activemodel-5.2.2/lib/active_model/validations/validates.rb:114:in `validates'
from /home/tomeraberbach/Desktop/msf/src/app/models/user.rb:7:in `<class:User>'
from /home/tomeraberbach/Desktop/msf/src/app/models/user.rb:4:in `<main>'
from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:50:in `load'
from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:50:in `load'
from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:476:in `block in load_file'
from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:661:in `new_constants_in'
from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:475:in `load_file'
from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:373:in `block in require_or_load'
from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:37:in `block in load_interlock'
from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies/interlock.rb:14:in `block in loading'
from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/concurrency/share_lock.rb:151:in `exclusive'
from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies/interlock.rb:13:in `loading'
from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:37:in `load_interlock'
from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:356:in `require_or_load'
from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:46:in `block in require_or_load'
from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:16:in `allow_bootsnap_retry'
from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:45:in `require_or_load'
from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:510:in `load_missing_constant'
from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:58:in `block in load_missing_constant'
from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:16:in `allow_bootsnap_retry'
from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:57:in `load_missing_constant'
from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:195:in `const_missing'
from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/inflector/methods.rb:283:in `const_get'
from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/inflector/methods.rb:283:in `block in constantize'
from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/inflector/methods.rb:281:in `each'
from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/inflector/methods.rb:281:in `inject'
from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/inflector/methods.rb:281:in `constantize'
from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:582:in `get'
from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:613:in `constantize'
from /var/lib/gems/2.5.0/gems/devise-4.5.0/lib/devise.rb:316:in `get'
from /var/lib/gems/2.5.0/gems/devise-4.5.0/lib/devise/mapping.rb:83:in `to'
from /var/lib/gems/2.5.0/gems/devise-4.5.0/lib/devise/mapping.rb:78:in `modules'
from /var/lib/gems/2.5.0/gems/devise-4.5.0/lib/devise/mapping.rb:95:in `routes'
from /var/lib/gems/2.5.0/gems/devise-4.5.0/lib/devise/mapping.rb:162:in `default_used_route'
from /var/lib/gems/2.5.0/gems/devise-4.5.0/lib/devise/mapping.rb:72:in `initialize'
from /var/lib/gems/2.5.0/gems/devise-4.5.0/lib/devise.rb:346:in `new'
from /var/lib/gems/2.5.0/gems/devise-4.5.0/lib/devise.rb:346:in `add_mapping'
from /var/lib/gems/2.5.0/gems/devise-4.5.0/lib/devise/rails/routes.rb:243:in `block in devise_for'
from /var/lib/gems/2.5.0/gems/devise-4.5.0/lib/devise/rails/routes.rb:242:in `each'
from /var/lib/gems/2.5.0/gems/devise-4.5.0/lib/devise/rails/routes.rb:242:in `devise_for'
from /home/tomeraberbach/Desktop/msf/src/config/routes.rb:3:in `block (2 levels) in <main>'
from /var/lib/gems/2.5.0/gems/actionpack-5.2.2/lib/action_dispatch/routing/mapper.rb:879:in `scope'
from /home/tomeraberbach/Desktop/msf/src/config/routes.rb:2:in `block in <main>'
from /var/lib/gems/2.5.0/gems/actionpack-5.2.2/lib/action_dispatch/routing/route_set.rb:432:in `instance_exec'
from /var/lib/gems/2.5.0/gems/actionpack-5.2.2/lib/action_dispatch/routing/route_set.rb:432:in `eval_block'
from /var/lib/gems/2.5.0/gems/actionpack-5.2.2/lib/action_dispatch/routing/route_set.rb:414:in `draw'
from /home/tomeraberbach/Desktop/msf/src/config/routes.rb:1:in `<main>'
from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:50:in `load'
from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:50:in `load'
from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:285:in `block in load'
from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:285:in `load'
from /var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/application/routes_reloader.rb:41:in `block in load_paths'
from /var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/application/routes_reloader.rb:41:in `each'
from /var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/application/routes_reloader.rb:41:in `load_paths'
from /var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/application/routes_reloader.rb:20:in `reload!'
from /var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/application/routes_reloader.rb:30:in `block in updater'
from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/file_update_checker.rb:83:in `execute'
from /var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/application/routes_reloader.rb:10:in `execute'
from /var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/application/finisher.rb:130:in `block in <module:Finisher>'
from /var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:32:in `instance_exec'
from /var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:32:in `run'
from /var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:61:in `block in run_initializers'
from /usr/lib/ruby/2.5.0/tsort.rb:228:in `block in tsort_each'
from /usr/lib/ruby/2.5.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
from /usr/lib/ruby/2.5.0/tsort.rb:431:in `each_strongly_connected_component_from'
from /usr/lib/ruby/2.5.0/tsort.rb:349:in `block in each_strongly_connected_component'
from /usr/lib/ruby/2.5.0/tsort.rb:347:in `each'
from /usr/lib/ruby/2.5.0/tsort.rb:347:in `call'
from /usr/lib/ruby/2.5.0/tsort.rb:347:in `each_strongly_connected_component'
from /usr/lib/ruby/2.5.0/tsort.rb:226:in `tsort_each'
from /usr/lib/ruby/2.5.0/tsort.rb:205:in `tsort_each'
from /var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:60:in `run_initializers'
from /var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/application.rb:361:in `initialize!'
from /home/tomeraberbach/Desktop/msf/src/config/environment.rb:5:in `<main>'
from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:102:in `preload'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:153:in `serve'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
from /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
from /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
from -e:1:in `<main>'
My User class:
##
# A class representing a user account for this web application
# Instances of this class represent rows in the +users+ table on the database.
class User < ApplicationRecord
# Validation
validates_presence_of :email, :encrypted_password
validates :email, email: true
# Associations
devise :database_authenticatable, :registerable, :recoverable,
:rememberable, :trackable, :validatable
has_and_belongs_to_many :roles
# Events
before_validation do
# Removes unnecessary whitespace
self.email = email.strip
end
end
Any ideas?
I figured out the problem. The self.abstract_class = true line in RegexValidator was silently raising an error because there is no self.abstract_class method in the class. I thought there was because I saw it in the ApplicationRecord class, but I now realize that this is defined in the ActiveRecord::Base class.
I determined this by adding require_relative "../validators/email_validator" to the top of the user.rb file. After doing that I was able to see the error which was silent before:
/home/tomeraberbach/Desktop/msf/src/app/validators/regex_validator.rb:4:in `<class:RegexValidator>': undefined method `abstract_class=' for RegexValidator:Class (NoMethodError)
After removing the self.abstract_class = true line and the require_relative "../validators/email_validator" line, the problem was resolved.

Circular dependency on nested concern

Any got any idea why, on my production server I can't use nested concerns in model?
I have a model Landing
class Landing < ActiveRecord::Base
include Claimable
end
and concern
module Claimable
extend ActiveSupport::Concern
end
Everything is working fine, but Claimable is stricly Landing logic so I would like to put it a nested route
class Landing < ActiveRecord::Base
include Landing::Claimable
end
and
module Landing::Claimable
extend ActiveSupport::Concern
end
This is working on my developement machine (OSX Yosemite), but when I deploy to a Linux production server I receive error:
/home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:492:in `load_missing_constant': Circular dependency detected while autoloading constant Landing::Claimable (RuntimeError)
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:184:in `const_missing'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/app/models/landing.rb:20:in `<class:Landing>'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/app/models/landing.rb:18:in `<top (required)>'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `block in require'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:360:in `require_or_load'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:494:in `load_missing_constant'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:184:in `const_missing'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/app/models/concerns/landing/claimable.rb:1:in `<top (required)>'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `block in require'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:360:in `require_or_load'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:317:in `depend_on'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:233:in `require_dependency'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0/lib/rails/engine.rb:472:in `block (2 levels) in eager_load!'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0/lib/rails/engine.rb:471:in `each'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0/lib/rails/engine.rb:471:in `block in eager_load!'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0/lib/rails/engine.rb:469:in `each'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0/lib/rails/engine.rb:469:in `eager_load!'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0/lib/rails/engine.rb:346:in `eager_load!'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0/lib/rails/application/finisher.rb:56:in `each'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0/lib/rails/application/finisher.rb:56:in `block in <module:Finisher>'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `instance_exec'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `run'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0/lib/rails/initializable.rb:55:in `block in run_initializers'
from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `each'
from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `call'
from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0/lib/rails/initializable.rb:54:in `run_initializers'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/railties-4.2.0/lib/rails/application.rb:352:in `initialize!'
from /home/app/app/current/config/environment.rb:5:in `<top (required)>'
from /home/app/app/current/config.ru:3:in `require'
from /home/app/app/current/config.ru:3:in `block in <main>'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/rack-1.6.0/lib/rack/builder.rb:55:in `instance_eval'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/rack-1.6.0/lib/rack/builder.rb:55:in `initialize'
from /home/app/app/current/config.ru:1:in `new'
from /home/app/app/current/config.ru:1:in `<main>'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/thin-1.6.3/lib/rack/adapter/loader.rb:33:in `eval'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/thin-1.6.3/lib/rack/adapter/loader.rb:33:in `load'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/thin-1.6.3/lib/rack/adapter/loader.rb:42:in `for'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/thin-1.6.3/lib/thin/controllers/controller.rb:170:in `load_adapter'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/thin-1.6.3/lib/thin/controllers/controller.rb:74:in `start'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/thin-1.6.3/lib/thin/runner.rb:200:in `run_command'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/thin-1.6.3/lib/thin/runner.rb:156:in `run!'
from /home/app/app/releases/a34cd4a786d8f6c35179fb8eebc34469f471192a/vendor/bundle/ruby/2.1.0/gems/thin-1.6.3/bin/thin:6:in `<top (required)>'
from /home/app/app/releases/68f6492bb01f28373b95f26f34b609fdb99dc9cd/vendor/bundle/bin/thin:16:in `load'
from /home/app/app/releases/68f6492bb01f28373b95f26f34b609fdb99dc9cd/vendor/bundle/bin/thin:16:in `<main>'
This usually has to do with your config.eager_load settings on your application. You have a different setting in the production environment from the development one, which is perfectly normal and the intended use, but that's why you experience different behaviors from development to production.
As a possible solution, I suggest you avoid using the one-line namespaced class definition and change it to multiple lines instead.
Try changing:
module Landing::Claimable
end
to:
module Landing
module Claimable
end
end

Error integrating piggybak with rails admin. Undefined method 'nestable'

I try to integrate piggybak in my rails application, using the example initializer for rails_admin from
https://github.com/piggybak/demo/blob/master/config/initializers/rails_admin.rb
When I try to start up the server I get the following error:
/home/dumand/Desktop/Projects/3dgreen/config/initializers/rails_admin.rb:32:in block (2 levels) in <top (required)>': undefined methodnestable' for RailsAdmin::Config::Actions:Module (NoMethodError)
This is the server log:
/home/dumand/Desktop/Projects/3dgreen/config/initializers/rails_admin.rb:32:in `block (2 levels) in <top (required)>': undefined method `nestable' for RailsAdmin::Config::Actions:Module (NoMethodError)
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/rails_admin-0.6.3/lib/rails_admin/config.rb:239:in `instance_eval'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/rails_admin-0.6.3/lib/rails_admin/config.rb:239:in `actions'
from /home/dumand/Desktop/Projects/3dgreen/config/initializers/rails_admin.rb:21:in `block in <top (required)>'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/rails_admin-0.6.3/lib/rails_admin.rb:29:in `call'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/rails_admin-0.6.3/lib/rails_admin.rb:29:in `config'
from /home/dumand/Desktop/Projects/3dgreen/config/initializers/rails_admin.rb:1:in `<top (required)>'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `load'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `block in load'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `load'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/engine.rb:609:in `block (2 levels) in <class:Engine>'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/engine.rb:608:in `each'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/engine.rb:608:in `block in <class:Engine>'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `instance_exec'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `run'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:55:in `block in run_initializers'
from /home/dumand/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
from /home/dumand/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
from /home/dumand/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/tsort.rb:418:in `block (2 levels) in each_strongly_connected_component_from'
from /home/dumand/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
from /home/dumand/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/tsort.rb:417:in `block in each_strongly_connected_component_from'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:44:in `each'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:44:in `tsort_each_child'
from /home/dumand/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/tsort.rb:411:in `call'
from /home/dumand/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/tsort.rb:411:in `each_strongly_connected_component_from'
from /home/dumand/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
from /home/dumand/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/tsort.rb:345:in `each'
from /home/dumand/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/tsort.rb:345:in `call'
from /home/dumand/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
from /home/dumand/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
from /home/dumand/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:54:in `run_initializers'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/application.rb:215:in `initialize!'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /home/dumand/Desktop/Projects/3dgreen/config/environment.rb:5:in `<top (required)>'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `block in require'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
from /home/dumand/Desktop/Projects/3dgreen/config.ru:3:in `block in <main>'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
from /home/dumand/Desktop/Projects/3dgreen/config.ru:in `new'
from /home/dumand/Desktop/Projects/3dgreen/config.ru:in `<main>'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/commands/server.rb:48:in `app'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/commands/server.rb:75:in `start'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/commands.rb:76:in `block in <top (required)>'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/commands.rb:71:in `tap'
from /home/dumand/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/commands.rb:71:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
and here is rails_admin initializer:
RailsAdmin.config do |config|
config.main_app_name = ["3D Green"]
### Popular gems integration
## == Devise ==
# config.authenticate_with do
# warden.authenticate! scope: :user
# end
# config.current_user_method(&:current_user)
## == Cancan ==
# config.authorize_with :cancan
## == PaperTrail ==
# config.audit_with :paper_trail, 'User', 'PaperTrail::Version' # PaperTrail >= 3.0.0
### More at https://github.com/sferik/rails_admin/wiki/Base-configuration
config.actions do
dashboard # mandatory
index # mandatory
new
export
bulk_delete
show
edit
delete
show_in_app
nestable do
visible do
[::PiggybakTaxonomy::NavigationNode].include? bindings[:abstract_model].model
end
end
## With an audit adapter, you can add:
# history_index
# history_show
config.model Product do
edit do
include_all_fields
end
end
end
end
Try it with removing nestable taxanomy code because it seems that you didn't uses nested taxanomy as per your models also

Load error in Rspec and full Rails engine

I am trying to migrate Rails app to use Rails engines. My plan is to not use mountable engines for now and migrate to them later.
Folders structure looks like this:
config
engines
common
app
models
lib
common
namespaced_lib
web
app
controllers
helpers
views
config
features
lib
public
script
spec
vendor
Engines are defined like this:
module Common
class Engine < ::Rails::Engine
engine_dir = File.expand_path('../..', File.dirname(__FILE__))
config.autoload_paths += Dir[engine_dir + '/app/models/**/']
config.autoload_paths += Dir[engine_dir + '/lib/**/']
end
end
module Web
class Engine < ::Rails::Engine
end
end
There is a Data class in lib/common/namespaced_lib folder of Common engine. In code it is referenced only as NamespacedLib::Data and never as Data.
module NamespacedLib
class Data
end
end
And there is a DataController (inside of engines/web/app/controllers):
class DataController < ApplicationController
end
When I run rspec I get following error. This error never happened before I moved to engines.
rspec
/.rvm/gems/ruby-2.1.2/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:503:in `load_missing_constant': Expected /engines/common/lib/common/namespaced_lib/data.rb to define Data (LoadError)
from /.rvm/gems/ruby-2.1.2/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:192:in `block in const_missing'
from /.rvm/gems/ruby-2.1.2/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:190:in `each'
from /.rvm/gems/ruby-2.1.2/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:190:in `const_missing'
from /.rvm/gems/ruby-2.1.2/gems/activesupport-3.2.19/lib/active_support/inflector/methods.rb:230:in `block in constantize'
from /.rvm/gems/ruby-2.1.2/gems/activesupport-3.2.19/lib/active_support/inflector/methods.rb:229:in `each'
from /.rvm/gems/ruby-2.1.2/gems/activesupport-3.2.19/lib/active_support/inflector/methods.rb:229:in `constantize'
from /.rvm/gems/ruby-2.1.2/gems/activesupport-3.2.19/lib/active_support/inflector/methods.rb:260:in `safe_constantize'
from /.rvm/gems/ruby-2.1.2/gems/activesupport-3.2.19/lib/active_support/core_ext/string/inflections.rb:66:in `safe_constantize'
from /.rvm/gems/ruby-2.1.2/gems/actionpack-3.2.19/lib/action_controller/metal/params_wrapper.rb:152:in `_default_wrap_model'
from /.rvm/gems/ruby-2.1.2/gems/actionpack-3.2.19/lib/action_controller/metal/params_wrapper.rb:169:in `_set_wrapper_defaults'
from /.rvm/gems/ruby-2.1.2/gems/actionpack-3.2.19/lib/action_controller/metal/params_wrapper.rb:133:in `inherited'
from /.rvm/gems/ruby-2.1.2/gems/actionpack-3.2.19/lib/abstract_controller/railties/routes_helpers.rb:7:in `block (2 levels) in with'
from /.rvm/gems/ruby-2.1.2/gems/actionpack-3.2.19/lib/action_controller/railties/paths.rb:7:in `block (2 levels) in with'
from /engines/web/app/controllers/data_controller.rb:1:in `<top (required)>'
from /.rvm/gems/ruby-2.1.2/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:251:in `require'
from /.rvm/gems/ruby-2.1.2/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:251:in `block in require'
from /.rvm/gems/ruby-2.1.2/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:236:in `load_dependency'
from /.rvm/gems/ruby-2.1.2/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:251:in `require'
from /.rvm/gems/ruby-2.1.2/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:359:in `require_or_load'
from /.rvm/gems/ruby-2.1.2/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:313:in `depend_on'
from /.rvm/gems/ruby-2.1.2/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:225:in `require_dependency'
from /.rvm/gems/ruby-2.1.2/gems/railties-3.2.19/lib/rails/engine.rb:444:in `block (2 levels) in eager_load!'
from /.rvm/gems/ruby-2.1.2/gems/railties-3.2.19/lib/rails/engine.rb:443:in `each'
from /.rvm/gems/ruby-2.1.2/gems/railties-3.2.19/lib/rails/engine.rb:443:in `block in eager_load!'
from /.rvm/gems/ruby-2.1.2/gems/railties-3.2.19/lib/rails/engine.rb:441:in `each'
from /.rvm/gems/ruby-2.1.2/gems/railties-3.2.19/lib/rails/engine.rb:441:in `eager_load!'
from /.rvm/gems/ruby-2.1.2/gems/railties-3.2.19/lib/rails/application/railties.rb:8:in `each'
from /.rvm/gems/ruby-2.1.2/gems/railties-3.2.19/lib/rails/application/railties.rb:8:in `all'
from /.rvm/gems/ruby-2.1.2/gems/railties-3.2.19/lib/rails/engine.rb:439:in `eager_load!'
from /.rvm/gems/ruby-2.1.2/gems/railties-3.2.19/lib/rails/application/finisher.rb:53:in `block in <module:Finisher>'
from /.rvm/gems/ruby-2.1.2/gems/railties-3.2.19/lib/rails/initializable.rb:30:in `instance_exec'
from /.rvm/gems/ruby-2.1.2/gems/railties-3.2.19/lib/rails/initializable.rb:30:in `run'
from /.rvm/gems/ruby-2.1.2/gems/railties-3.2.19/lib/rails/initializable.rb:55:in `block in run_initializers'
from /.rvm/gems/ruby-2.1.2/gems/railties-3.2.19/lib/rails/initializable.rb:54:in `each'
from /.rvm/gems/ruby-2.1.2/gems/railties-3.2.19/lib/rails/initializable.rb:54:in `run_initializers'
from /.rvm/gems/ruby-2.1.2/gems/railties-3.2.19/lib/rails/application.rb:136:in `initialize!'
from /.rvm/gems/ruby-2.1.2/gems/railties-3.2.19/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /config/environment.rb:14:in `<top (required)>'
from /spec/spec_helper.rb:46:in `require'
from /spec/spec_helper.rb:46:in `block in <top (required)>'
from /.rvm/gems/ruby-2.1.2/gems/spork-0.9.2/lib/spork.rb:24:in `prefork'
from /spec/spec_helper.rb:40:in `<top (required)>'
from /spec/controllers/approvals_controller_spec.rb:1:in `require'
from /spec/controllers/approvals_controller_spec.rb:1:in `<top (required)>'
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `load'
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `each'
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `load_spec_files'
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:22:in `run'
from /.rvm/gems/ruby-2.1.2/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:80:in `run'
I tried to rename DataController to DataRenamedController and the error went away. So it looks like Rails or Rspec tries to auto-load Data class when it sees DataController. Is there a way to disable this?

Define meta class methods using modules

I want to be able to create meta class method. For exemple, I have an autocomplete mechanisme on my website working with select_tags.
Here is how I would like to build my select options:
f.select(:subjects, options_from_collection_for_select(Subject.autocomplete_for_subject_title, :id, :title))
So my autocomplete_for_subject_title class method could return for now Subject.all
I was thinking about a module than defines a class method for a given model, something like this :
Subject.rb
class Subject
include SimpleAutocomplete
field :title, :type => String
autocomplete_for :subject, :title
end
lib/simple_autocomplete.rb
module SimpleAutocomplete
def self.included(base)
base.class_eval do |klass|
extend ClassMethods
end
end
module ClassMethods
def autocomplete_for(object, method, options = {}, &block)
(class << object; object; end).instance_eval { define_method "autocomplete_for_#{object}_#{method}" do
puts "It works!"
end
}
end
end
end
But when I launch rails server, here is what I've got :
simple_autocomplete.rb:13:in `autocomplete_for': can't define singleton (TypeError)
from /Users/pierrelouisgottfrois/Work/teamento_beta_git/app/models/subject.rb:20:in `<class:Subject>'
from /Users/pierrelouisgottfrois/Work/teamento_beta_git/app/models/subject.rb:1:in `<top (required)>'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.4/lib/active_support/dependencies.rb:454:in `load'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.4/lib/active_support/dependencies.rb:454:in `block in load_file'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.4/lib/active_support/dependencies.rb:596:in `new_constants_in'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.4/lib/active_support/dependencies.rb:453:in `load_file'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.4/lib/active_support/dependencies.rb:340:in `require_or_load'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.4/lib/active_support/dependencies.rb:300:in `depend_on'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.4/lib/active_support/dependencies.rb:216:in `require_dependency'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/mongoid-2.0.2/lib/rails/mongoid.rb:55:in `load_model'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/mongoid-2.0.2/lib/rails/mongoid.rb:18:in `block (2 levels) in load_models'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/mongoid-2.0.2/lib/rails/mongoid.rb:17:in `each'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/mongoid-2.0.2/lib/rails/mongoid.rb:17:in `block in load_models'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.4/lib/rails/paths.rb:102:in `block in each'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.4/lib/rails/paths.rb:102:in `each'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.4/lib/rails/paths.rb:102:in `each'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/mongoid-2.0.2/lib/rails/mongoid.rb:16:in `load_models'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/mongoid-2.0.2/lib/mongoid/railtie.rb:86:in `block (2 levels) in <class:Railtie>'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.4/lib/active_support/callbacks.rb:419:in `_run_prepare_callbacks'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.4/lib/action_dispatch/middleware/callbacks.rb:40:in `initialize'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.4/lib/action_dispatch/middleware/stack.rb:33:in `new'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.4/lib/action_dispatch/middleware/stack.rb:33:in `build'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.4/lib/action_dispatch/middleware/stack.rb:79:in `block in build'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.4/lib/action_dispatch/middleware/stack.rb:79:in `each'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.4/lib/action_dispatch/middleware/stack.rb:79:in `inject'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.4/lib/action_dispatch/middleware/stack.rb:79:in `build'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.4/lib/rails/application.rb:162:in `app'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.4/lib/rails/application/finisher.rb:35:in `block in <module:Finisher>'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.4/lib/rails/initializable.rb:25:in `instance_exec'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.4/lib/rails/initializable.rb:25:in `run'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.4/lib/rails/initializable.rb:50:in `block in run_initializers'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.4/lib/rails/initializable.rb:49:in `each'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.4/lib/rails/initializable.rb:49:in `run_initializers'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.4/lib/rails/application.rb:134:in `initialize!'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.4/lib/rails/application.rb:77:in `method_missing'
from /Users/pierrelouisgottfrois/Work/teamento_beta_git/config/environment.rb:10:in `<top (required)>'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.4/lib/active_support/dependencies.rb:239:in `require'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.4/lib/active_support/dependencies.rb:239:in `block in require'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.4/lib/active_support/dependencies.rb:225:in `block in load_dependency'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.4/lib/active_support/dependencies.rb:596:in `new_constants_in'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.4/lib/active_support/dependencies.rb:225:in `load_dependency'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.4/lib/active_support/dependencies.rb:239:in `require'
from /Users/pierrelouisgottfrois/Work/teamento_beta_git/config.ru:3:in `block in <main>'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.1/lib/rack/builder.rb:46:in `instance_eval'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.1/lib/rack/builder.rb:46:in `initialize'
from /Users/pierrelouisgottfrois/Work/teamento_beta_git/config.ru:1:in `new'
from /Users/pierrelouisgottfrois/Work/teamento_beta_git/config.ru:1:in `<main>'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.1/lib/rack/builder.rb:35:in `eval'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.1/lib/rack/builder.rb:35:in `parse_file'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.1/lib/rack/server.rb:162:in `app'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.1/lib/rack/server.rb:248:in `wrapped_app'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.1/lib/rack/server.rb:213:in `start'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.4/lib/rails/commands/server.rb:65:in `start'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.4/lib/rails/commands.rb:30:in `block in <top (required)>'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.4/lib/rails/commands.rb:27:in `tap'
from /Users/pierrelouisgottfrois/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.4/lib/rails/commands.rb:27:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I've read this blog post to start: http://blog.jayfields.com/2007/10/ruby-defining-class-methods.html
Do you have any idea ?
You're trying to invoke the singleton class of object, via class << object - but object is the symbol :subject, which I don't think is what you want.
I'm not sure what you do want, mind you, but that might help you figure it out.

Resources