sunspot_configuration.rb:52:in `block in <top (required)>': undefined method `gsub' for nil:NilClass

79 views
Skip to first unread message

agusddt

unread,
Jul 22, 2015, 12:17:29 PM7/22/15
to Ruby on Rails: Talk
I was uploading my app to a server, put it in production mode on the server, still on development mode locally and suddenly I cannot run "rails server" anymores since it dies automatically with this error:

/Users/agusddt/developments/crm/config/initializers/sunspot_configuration.rb:52:in `block in <top (required)>': undefined method `gsub' for nil:NilClass (NoMethodError)

from /Users/agusddt/developments/crm/config/initializers/sunspot_configuration.rb:45:in `each'

from /Users/agusddt/developments/crm/config/initializers/sunspot_configuration.rb:45:in `<top (required)>'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in `load'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in `block in load'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:in `load_dependency'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in `load'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/engine.rb:652:in `block in load_config_initializer'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/notifications.rb:166:in `instrument'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/engine.rb:651:in `load_config_initializer'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/engine.rb:616:in `block (2 levels) in <class:Engine>'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/engine.rb:615:in `each'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/engine.rb:615:in `block in <class:Engine>'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/initializable.rb:30:in `instance_exec'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/initializable.rb:30:in `run'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/initializable.rb:55:in `block in run_initializers'

from /Users/agusddt/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'

from /Users/agusddt/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'

from /Users/agusddt/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:418:in `block (2 levels) in each_strongly_connected_component_from'

from /Users/agusddt/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'

from /Users/agusddt/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:417:in `block in each_strongly_connected_component_from'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/initializable.rb:44:in `each'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/initializable.rb:44:in `tsort_each_child'

from /Users/agusddt/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:411:in `call'

from /Users/agusddt/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:411:in `each_strongly_connected_component_from'

from /Users/agusddt/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'

from /Users/agusddt/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:345:in `each'

from /Users/agusddt/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:345:in `call'

from /Users/agusddt/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'

from /Users/agusddt/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'

from /Users/agusddt/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/initializable.rb:54:in `run_initializers'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/application.rb:352:in `initialize!'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/railtie.rb:194:in `public_send'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/railtie.rb:194:in `method_missing'

from /Users/agusddt/developments/crm/config/environment.rb:5:in `<top (required)>'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `require'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `block in require'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:in `load_dependency'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `require'

from /Users/agusddt/developments/crm/config.ru:3:in `block in <main>'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize'

from /Users/agusddt/developments/crm/config.ru:in `new'

from /Users/agusddt/developments/crm/config.ru:in `<main>'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/rack-1.6.4/lib/rack/builder.rb:49:in `eval'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/rack-1.6.4/lib/rack/builder.rb:49:in `new_from_string'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/rack-1.6.4/lib/rack/builder.rb:40:in `parse_file'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/rack-1.6.4/lib/rack/server.rb:299:in `build_app_and_options_from_config'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/rack-1.6.4/lib/rack/server.rb:208:in `app'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/commands/server.rb:61:in `app'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/rack-1.6.4/lib/rack/server.rb:336:in `wrapped_app'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/commands/server.rb:139:in `log_to_stdout'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/commands/server.rb:78:in `start'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:80:in `block in server'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:75:in `tap'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:75:in `server'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:39:in `run_command!'

from /Users/agusddt/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/commands.rb:17:in `<top (required)>'

from bin/rails:4:in `require'

from bin/rails:4:in `<main>'


Taking a look into the logs appears just a warning:

DEPRECATION WARNING: Currently, Active Record suppresses errors raised within `after_rollback`/`after_commit` callbacks and only print them to the logs. In the next version, these errors will no longer be suppressed. Instead, the errors will propagate normally just like in other Active Record callbacks.


You can opt into the new behavior and remove this warning by setting:


  config.active_record.raise_in_transactional_callbacks = true


 (called from <class:Asset> at /Users/agusddt/developments/crm/app/models/asset.rb:21)


But it seems the error is associated to asset.rb


Anyone can help me? I tried serveral things but I just do not know what else to do.

Thanks!

Frederick Cheung

unread,
Jul 22, 2015, 12:20:04 PM7/22/15
to Ruby on Rails: Talk, agu...@gmail.com


On Wednesday, July 22, 2015 at 5:17:29 PM UTC+1, agusddt wrote:
I was uploading my app to a server, put it in production mode on the server, still on development mode locally and suddenly I cannot run "rails server" anymores since it dies automatically with this error:

/Users/agusddt/developments/crm/config/initializers/sunspot_configuration.rb:52:in `block in <top (required)>': undefined method `gsub' for nil:NilClass (NoMethodError)

from /Users/agusddt/developments/crm/config/initializers/sunspot_configuration.rb:45:in `each'

from /Users/agusddt/developments/crm/config/initializers/sunspot_configuration.rb:45:in `<top (required)>'


[snip] 


Taking a look into the logs appears just a warning:

DEPRECATION WARNING: Currently, Active Record suppresses errors raised within `after_rollback`/`after_commit` callbacks and only print them to the logs. In the next version, these errors will no longer be suppressed. Instead, the errors will propagate normally just like in other Active Record callbacks.



I doubt this warning is relevant - the probably is almost certainly  in config/initializers/sunspot_configuration.rb:52

Fred

agusddt

unread,
Jul 22, 2015, 12:52:43 PM7/22/15
to Ruby on Rails: Talk
Fred, thanks for your answer. 
The thing is that I cannot run "rails server"on localhost, it terminates immediately.

agusddt

unread,
Jul 22, 2015, 1:05:44 PM7/22/15
to Ruby on Rails: Talk
I even uninstalled sunspot_Rails, sunspot_solr and their dependencies and still gices me the error and would not let me run "rails server"on localhost

Colin Law

unread,
Jul 22, 2015, 2:28:02 PM7/22/15
to rubyonra...@googlegroups.com
On 22 July 2015 at 17:52, agusddt <agu...@gmail.com> wrote:
> Fred, thanks for your answer.
> The thing is that I cannot run "rails server"on localhost, it terminates
> immediately.

You have not said what is in
config/initializers/sunspot_configuration.rb:52 as suggested by Fred

Colin
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/62f3862d-460f-4b4c-a7b7-a31e4b887935%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

agusddt

unread,
Jul 22, 2015, 3:21:07 PM7/22/15
to Ruby on Rails: Talk
Sorry about that, problem is on line highlighted.
This is sunspot_configuration.rb:

ActiveRecord::Base.class_eval do
  class << self
    alias_method :super_searchable, :searchable
    def searchable(*args, &block)
      Search::Models.register self
      Sunspot::DSL::Fields.instance_variable_set '@current_model', self
      super_searchable(*args, &block)
    end

    def searchable_fields
      @searchable_fields ||= {}
    end
  end
end

Sunspot::DSL::Fields.class_eval do
  alias_method :super_text, :text
  def text(*args, &block)
    super_text(*args, &block)
    register_fields 'text', args
  end

  alias_method :super_method_missing, :method_missing
  def method_missing(name, *args, &block)
    super_method_missing(name, *args, &block)
    register_fields name, args
  end

  private
  def register_fields(search_type, fields)
    fields.each do |field|
      current_model.searchable_fields[field.to_sym] = Search::Field.new(
        current_model, field.to_sym, search_type.to_sym)
    end
  end
  def current_model
    Sunspot::DSL::Fields.instance_variable_get '@current_model'
  end
end

require_relative 'sunspot_custom_types'
require Rails.root + 'lib/util/generic_decorators.rb'
# Eager load all the models so that the search data is readily available
require Rails.root + 'app/models/search.rb'
Dir[Rails.root + 'app/models/**/*.rb'].each do |file|
  next if file.include?('/concerns/') || file.include?('/freshdesk_local/')

  if file.include? '/liquid/'
    require file
  else
    /app\/models\/(?<model_name>[\w\/]+\.rb)/ =~ file
    Kernel.const_get "#{model_name.gsub('.rb', '').camelize}"
  end
end

Colin Law

unread,
Jul 22, 2015, 3:27:41 PM7/22/15
to rubyonra...@googlegroups.com
On 22 July 2015 at 20:21, agusddt <agu...@gmail.com> wrote:
> Sorry about that, problem is on line highlighted.
> This is sunspot_configuration.rb:
> ...
>>> Kernel.const_get "#{model_name.gsub('.rb', '').camelize}"

Well, as the error indicates, presumably model_name is nil

Colin

tamouse pontiki

unread,
Jul 23, 2015, 10:04:30 PM7/23/15
to rubyonra...@googlegroups.com
On Wed, Jul 22, 2015 at 10:45 AM, agusddt <agu...@gmail.com> wrote:
I was uploading my app to a server, put it in production mode on the server, still on development mode locally and suddenly I cannot run "rails server" anymores since it dies automatically with this error:

/Users/agusddt/developments/crm/config/initializers/sunspot_configuration.rb:52:in `block in <top (required)>': undefined method `gsub' for nil:NilClass (NoMethodError)

I'm very curious about what you're describing. You're remark above about uploading to your server notwithstanding, your local development environment shouldn't have changed at all simply because you uploaded your app someplace else. Did you remove or change something from your development environment when you uploaded? If not, there must be something quite else going on.

As this worked in development before, perhaps if you were to ensure your local environment can roll back to a previous version that's known to work.

Are you seeing problems in production or is everything there working well?


Agustina Diaz de Tuesta

unread,
Jul 23, 2015, 10:17:25 PM7/23/15
to rubyonra...@googlegroups.com
Thanks for your answer!

I understand that It shouldn't have changed just because I uploaded it, the thing is I did make some minor changes (on the views) and upload them without checking on the local host but on the remote server. Everything is working perfectly on the server under production, the only solution I found was to uninstall the gems and delete all associated configuration. Upon doing that it worked fine locally but the thing is I do need to use the gem Sunspot, so tried to install it back and it stopped running again.

I commented the line that was giving me trouble just for now to keep working, but o don't understand what could have happened, since I'm pretty sure I did not mess on the configuration locally when uploading.
--
You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-talk/74sBRAiWkmE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rubyonrails-ta...@googlegroups.com.

To post to this group, send email to rubyonra...@googlegroups.com.

Colin Law

unread,
Jul 24, 2015, 2:43:03 AM7/24/15
to rubyonra...@googlegroups.com
On 24 July 2015 at 03:17, Agustina Diaz de Tuesta <agu...@gmail.com> wrote:
> Thanks for your answer!
>
> I understand that It shouldn't have changed just because I uploaded it, the
> thing is I did make some minor changes (on the views) and upload them
> without checking on the local host but on the remote server. Everything is
> working perfectly on the server under production, the only solution I found
> was to uninstall the gems and delete all associated configuration. Upon
> doing that it worked fine locally but the thing is I do need to use the gem
> Sunspot, so tried to install it back and it stopped running again.
>
> I commented the line that was giving me trouble just for now to keep
> working, but o don't understand what could have happened, since I'm pretty
> sure I did not mess on the configuration locally when uploading.

If you check out the previously working version from your source
control system and run bundle install then you should be back with a
working system. So all your automated tests should work, as should
rails s.

Colin
Reply all
Reply to author
Forward
0 new messages