Define meta class methods using modules - ruby-on-rails

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.

Related

finding model in rails gives "ArgumentError: no receiver given"

I just change the name of one of my models, it used to be "Course", and now it's "Booking", also I have created two brand new classes called "Course" and "Lesson" that both inherit from "Booking"
I have updated all the has_many in my models from :courses to :bookings, I made sure to rename the file to booking.rb, and renamed the table in the database to bookings.
When I run this in the rails console
Booking.find 1
I get this error
ArgumentError: no receiver given
The 2nd line below is the one causing the error
if filter.arity <= 0
lambda { |target, _| target.instance_exec(&filter) }
else
lambda { |target, _| target.instance_exec(target, &filter) }
end
Here is the stack trace
from ~/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:396:in `instance_exec'
from ~/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:396:in `block in make_lambda'
from ~/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:207:in `block in halting_and_conditional'
from ~/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:456:in `block in call'
from ~/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:456:in `each'
from ~/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:456:in `call'
from ~/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:101:in `__run_callbacks__'
from ~/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:750:in `_run_initialize_callbacks'
from ~/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/core.rb:350:in `init_with'
from ~/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/persistence.rb:69:in `instantiate'
from ~/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/querying.rb:50:in `block (2 levels) in find_by_sql'
from ~/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/result.rb:52:in `block in each'
from ~/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/result.rb:52:in `each'
from ~/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/result.rb:52:in `each'
from ~/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/querying.rb:50:in `map'
from ~/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/querying.rb:50:in `block in find_by_sql'
... 14 levels...
from ~/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands/console_helper.rb:9:in `start'
from ~/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:78:in `console'
from ~/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from ~/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `<top (required)>'
from ~/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
from ~/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `block in require'
from ~/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
from ~/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
from ~/fidka_app/bin/rails:38:in `<top (required)>'
from ~/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
from ~/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `block in load'
from ~/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
from ~/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
from ~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from ~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'

Cannot define multiple 'included' blocks for a Concern with sidekiq

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

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

ActiveAdmin Comment model not working properly

I created a blog by following the Getting Started with Rails precisely. And then I following the tutorial here to try ActiveAdmin: http://activeadmin.info/documentation.html.
It's working fine for the Post and Tag models (I logged in and created/add/edited stuff) but not the Comment model.
rails generate active_admin:resource Comment
create app/admin/comments.rb
Then when I try to start the server I get this:
rails server=> Booting WEBrick
=> Rails 3.0.7 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server Exiting /usr/local/lib/ruby/gems/1.9.1/gems/activeadmin-0.2.2/lib/active_admin/namespace.rb:116:in
`find_or_build_resource': Tried to
register Comment as Comment but
already registered to Comment
(ActiveAdmin::ResourceMismatchError)
from
/usr/local/lib/ruby/gems/1.9.1/gems/activeadmin-0.2.2/lib/active_admin/namespace.rb:45:in
`register' from
/usr/local/lib/ruby/gems/1.9.1/gems/activeadmin-0.2.2/lib/active_admin.rb:141:in
`register' from
/Users/myusername/Projects/RoR/blog/app/admin/comments.rb:1:in
`<top (required)>' from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:235:in
`load' from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:235:in
`block in load' from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:225:in
`block in load_dependency' from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:596:in
`new_constants_in' from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:225:in
`load_dependency' from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:235:in
`load' from
/usr/local/lib/ruby/gems/1.9.1/gems/activeadmin-0.2.2/lib/active_admin.rb:185:in
`block in load!' from
/usr/local/lib/ruby/gems/1.9.1/gems/activeadmin-0.2.2/lib/active_admin.rb:185:in
`each' from
/usr/local/lib/ruby/gems/1.9.1/gems/activeadmin-0.2.2/lib/active_admin.rb:185:in
`load!' from
/usr/local/lib/ruby/gems/1.9.1/gems/activeadmin-0.2.2/lib/active_admin.rb:212:in
`routes' from
/Users/myusername/Projects/RoR/blog/config/routes.rb:2:in
`block in <top (required)>' from
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/routing/route_set.rb:233:in
`instance_exec' from
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/routing/route_set.rb:233:in
`draw' from
/Users/myusername/Projects/RoR/blog/config/routes.rb:1:in
`<top (required)>' from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:235:in
`load' from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:235:in
`block in load' from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:225:in
`block in load_dependency' from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:596:in
`new_constants_in' from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:225:in
`load_dependency' from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:235:in
`load' from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:127:in `block in reload_routes!' from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:127:in `each' from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:127:in `reload_routes!' from
/usr/local/lib/ruby/gems/1.9.1/gems/activeadmin-0.2.2/lib/active_admin.rb:123:in
`block in setup' from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/callbacks.rb:420:in
`_run_prepare_callbacks' from
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/middleware/callbacks.rb:40:in
`initialize' from
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:33:in
`new' from
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:33:in
`build' from
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:79:in
`block in build' from
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:79:in
`each' from
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:79:in
`inject' from
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:79:in
`build' from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:162:in `app' from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application/finisher.rb:35:in
`block in <module:Finisher>' from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/initializable.rb:25:in `instance_exec' from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/initializable.rb:25:in `run' from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/initializable.rb:50:in `block in run_initializers' from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/initializable.rb:49:in `each' from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/initializable.rb:49:in `run_initializers' from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:134:in `initialize!' from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:77:in
`method_missing' from
/Users/myusername/Projects/RoR/blog/config/environment.rb:5:in
`<top (required)>' from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in
`require' from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in
`block in require' from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:225:in
`block in load_dependency' from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:596:in
`new_constants_in' from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:225:in
`load_dependency' from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in
`require' from
/Users/myusername/Projects/RoR/blog/config.ru:3:in
`block in <main>' from
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/builder.rb:46:in
`instance_eval' from
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/builder.rb:46:in
`initialize' from
/Users/myusername/Projects/RoR/blog/config.ru:1:in
`new' from
/Users/myusername/Projects/RoR/blog/config.ru:1:in
`<main>' from
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/builder.rb:35:in
`eval' from
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/builder.rb:35:in
`parse_file' from
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/server.rb:162:in
`app' from
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/server.rb:248:in
`wrapped_app' from
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/server.rb:213:in
`start' from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/commands/server.rb:65:in `start' from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/commands.rb:30:in
`block in <top (required)>' from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/commands.rb:27:in
`tap' from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/commands.rb:27:in
`<top (required)>' from
script/rails:6:in `require' from
script/rails:6:in `<main>'
Your help would be appreciated.
Look like a bug (ActiveAdmin has it's own built-in Comment model/class already): https://github.com/gregbell/active_admin/issues/64
A possible workaround could be to give your Comment model a different name within in app/admin/comments.rb:
ActiveAdmin.register Comment, :as => "PostComment" do
try this
run in terminal
rails g active_admin:resource ActiveAdmin::Comment
add a following lines in
app/admin/active_admin_comment.rb
ActiveAdmin.register ActiveAdmin::Comment, :as => "Comment" do
end
after that edit config/initializers/active_admin
[...]
config.comments_registration_name = "OldComment"
config.show_comments_in_menu = false
[...]
And now you have opportunity to customize a comments in app/admin/active_admin_comment.rb
but i still didn't find solution to add :update and :destroy actions
I had the same problem with version 1.0.0.pre, but thankfully, you can suppress ActiveAdmin comments altogether with a config in active_admin.rb then you don't have to alias your own Comment model anymore as mentioned above.
config/initializers/active_admin.rb
...
# == Admin Comments
#
# This allows your users to comment on any resource registered with Active Admin.
#
# You can completely disable comments:
config.allow_comments = false
#
It's also listed in the docs: https://github.com/gregbell/active_admin/blob/master/docs/1-general-configuration.md#comments
Dylan's answer is a great start. In addition to his, I needed to overwrite the controller resource/collection methods.
app/admin/comments.rb
ActiveAdmin.register Comment, as: 'QuestionComment' do
controller do
defaults resource_class: Comment, collection_name: 'comments', instance_name: 'comment'
end
end
Basically, you're just overwriting the defaults of inherited resource controller (https://github.com/josevalim/inherited_resources#overwriting-defaults)
(yes, this is still an issue in 2014 even in the 1.0.0 prerelease version, but it appears that they want to fix it from reading the github issues)

Resources