Question

Im struggling trying to make work a ruby on rails project of a friend in my computer. I'm currently working in ubuntu 12.04.

After setting up everything I got an error that I couldn't find anywhere. Here is the error message and the importer.rb file.

Any help would be great.

ERROR MESSAGE

developer@developer-VirtualBox:~/finantec$ rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
NameError: undefined method `context' for class `Importr::Importer'
/home/developer/finantec/vendor/engines/importr/lib/importr/importer.rb:15:in `alias_method'
/home/developer/finantec/vendor/engines/importr/lib/importr/importer.rb:15:in `<class:Importer>'
/home/developer/finantec/vendor/engines/importr/lib/importr/importer.rb:4:in `<module:Importr>'
/home/developer/finantec/vendor/engines/importr/lib/importr/importer.rb:3:in `<top (required)>'
/home/developer/finantec/app/importers/financial_institution_importer.rb:1:in `<top (required)>'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:424:in `load'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:424:in `block in load_file'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:616:in `new_constants_in'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:423:in `load_file'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:324:in `require_or_load'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:463:in `load_missing_constant'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:184:in `const_missing'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:226:in `const_get'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:226:in `block in constantize'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `each'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `inject'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `constantize'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/core_ext/string/inflections.rb:66:in `constantize'
/home/developer/finantec/vendor/engines/importr/lib/importr/active_admin.rb:8:in `data_import_interface'
/home/developer/finantec/app/admin/financial_institution.rb:4:in `block in <top (required)>'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/active_admin-ee996b09edb9/lib/active_admin/dsl.rb:15:in `instance_exec'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/active_admin-ee996b09edb9/lib/active_admin/dsl.rb:15:in `run_registration_block'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/active_admin-ee996b09edb9/lib/active_admin/namespace.rb:223:in `parse_registration_block'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/active_admin-ee996b09edb9/lib/active_admin/namespace.rb:48:in `register'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/active_admin-ee996b09edb9/lib/active_admin/application.rb:120:in `register'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/active_admin-ee996b09edb9/lib/active_admin.rb:76:in `register'
/home/developer/finantec/app/admin/financial_institution.rb:1:in `<top (required)>'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `load'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `block in load'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `load'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/active_admin-ee996b09edb9/lib/active_admin/application.rb:179:in `load'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/active_admin-ee996b09edb9/lib/active_admin/application.rb:171:in `block in load!'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/active_admin-ee996b09edb9/lib/active_admin/application.rb:171:in `each'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/active_admin-ee996b09edb9/lib/active_admin/application.rb:171:in `load!'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/active_admin-ee996b09edb9/lib/active_admin/application.rb:195:in `routes'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/active_admin-ee996b09edb9/lib/active_admin.rb:80:in `routes'
/home/developer/finantec/config/routes.rb:9:in `block in <top (required)>'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:341:in `instance_exec'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:341:in `eval_block'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:319:in `draw'
/home/developer/finantec/config/routes.rb:3:in `<top (required)>'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `load'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `block in load'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `load'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:40:in `each'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:40:in `load_paths'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:16:in `reload!'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:26:in `block in updater'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/file_update_checker.rb:75:in `call'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/file_update_checker.rb:75:in `execute'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:27:in `updater'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:6:in `execute_if_updated'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `instance_exec'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `run'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/initializable.rb:55:in `block in run_initializers'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:180:in `each'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/initializable.rb:54:in `run_initializers'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/application.rb:215:in `initialize!'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/developer/finantec/config/environment.rb:5:in `<top (required)>'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `block in require'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/application.rb:189:in `require_environment!'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/application.rb:250:in `block in run_tasks_blocks'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:240:in `call'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:240:in `block in execute'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:235:in `each'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:235:in `execute'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:201:in `block in invoke_prerequisites'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:199:in `each'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:199:in `invoke_prerequisites'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:178:in `block in invoke_with_call_chain'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:165:in `invoke'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/application.rb:150:in `invoke_task'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/application.rb:106:in `each'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/application.rb:106:in `block in top_level'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/application.rb:115:in `run_with_threads'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/application.rb:100:in `top_level'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/application.rb:78:in `block in run'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/application.rb:176:in `standard_exception_handling'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/application.rb:75:in `run'
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.2.2/bin/rake:33:in `<top (required)>'
/home/developer/.rvm/gems/ruby-2.0.0-p247@global/bin/rake:23:in `load'
/home/developer/.rvm/gems/ruby-2.0.0-p247@global/bin/rake:23:in `<main>'
/home/developer/.rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `eval'
/home/developer/.rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:migrate => environment

Importer.rb:

# require 'active_importer'

module Importr
  class Importer < ActiveImporter::Base
    def initialize(file, options = {})
      # TODO: ensure that data_import.model_class == self.class.model_class

      super

      if data_import && data_import.finished
        raise "Data import #{data_import.id} was already processed"
      end
    end

    alias_method :data_import, :context

    on :row_success do
      update_counters
      notify(:success, @counters)
    end

    on :row_error do |e|
      update_counters({index: row_index, error: e.message})
      notify(:error, @counters.merge(index: row_index, error: e.message))
    end

    on :import_failed do |e|
      notify(:base, error: e.message)
    end

    on :import_finished do
      data_import.update_attribute(:finished, true) if data_import
    end

    private

    def notify(subchannel, message)
      channel = ["/#{self.class}/#{subchannel}", data_import.try(:uuid)].compact.join("-")
      Importr::Notifier.notify(channel, message)
    end

    def update_counters(err= {})
      @counters = {
        success_count: row_success_count,
        error_count: row_error_count,
        processed_rows: row_processed_count,
        total_rows: row_count,
      }
      if data_import
        data_import.update_attributes(@counters) 
        add_error(err) unless err.blank?
      end
    end

    def add_error(err)
      data_import.update_attributes(error_messages: data_import.error_messages << err ) if data_import
    end
  end
end
Was it helpful?

Solution 3

I found the solution.

I was using a gem that was recently updated and they changed the name of the method.

Thanks to all for the help

OTHER TIPS

The error

NameError: undefined method context' for class Importr::Importer' 

on line

alias_method :data_import, :context

means that

you are trying to create an alias for a method named context which does not exist. Make sure that your class Importr::Importer or its ancestors have a method named context before aliasing it.

According to this, you should try using alias_attribute instead. The error may be something to do with weather or not your #context method exists on the class the first time it is called, and how Rails uses #method_missing

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top