首页 > 解决方案 > Updated to Rails 4.0, getting error: no implicit conversion of Symbol into Integer

问题描述

Upgraded gems (Rails 4.0 from Rails 3.2) and now am facing an error. This is the line causing the problem.

options[:autocomplete] ||= 'off'

options[:autocomplete] specifically is throwing the error when I use binding.pry. It seems that the a string is getting passed in as 'options', but this code is also used for hashes. The code worked fine before I upgraded to Rails 4.0 and upgraded a number of gems and deprecated code.

Another error that's related is 2 lines down:

label(name, options.delete(:label), :class => 'control-label')

which throws the error: wrong number of arguments (3 for 1..2). Both errors are from ActionView::Template::Error.

Here is the full method:

def #{selector}(name, options = {})
        options[:autocomplete] ||= 'off' #options = String ('Property')
        @template.content_tag(:div,
            label(name, options.fetch(:label, {}), :class => 'control-label') +          
            @template.content_tag(:div,
            super(name, options_with_errors(name, options)),
          :class => 'controls'),
        :class => class_with_errors(name, 'control-group'))
      end

I have changed options.delete to options.fetch as suggested in an answer by someone on the site.

I have also tried commenting parts out to test and changing parts of it, but it either throws more errors or removes large parts of the webpage form. E.g. When I remove one of the arguments in 'label()', I get the error: stack level too deep.

And here is my gemlist:

 $ bundle list
Gems included by the bundle:
  * actionmailer (4.0.0)
  * actionpack (4.0.0)
  * activemodel (4.0.0)
  * activerecord (4.0.0)
  * activerecord-deprecated_finders (1.0.4)
  * activesupport (4.0.0)
  * addressable (2.3.6)
  * annotate (2.6.3)
  * arel (4.0.2)
  * authlogic (3.4.1)
  * autoparse (0.3.3)
  * awesome_print (1.2.0)
  * aws-eventstream (1.0.2)
  * aws-partitions (1.149.0)
  * aws-sdk (1.38.0)
  * aws-sdk-core (3.48.3)
  * aws-sdk-kms (1.16.0)
  * aws-sdk-s3 (1.36.0)
  * aws-sigv4 (1.1.0)
  * bcrypt (3.1.7)
  * bcrypt-ruby (3.1.5)
  * builder (3.1.4)
  * bundler (1.17.3)
  * capybara (2.2.1)
  * celluloid (0.15.2)
  * celluloid-io (0.15.0)
  * ckeditor (4.0.6 f0d175a)
  * climate_control (0.0.3)
  * cocaine (0.5.4)
  * coderay (1.1.0)
  * coffee-rails (4.2.2)
  * coffee-script (2.4.1)
  * coffee-script-source (1.12.2)
  * concurrent-ruby (1.1.5)
  * daemons (1.1.9)
  * dalli (2.7.0)
  * database_cleaner (1.2.0)
  * delayed_job (4.0.1)
  * delayed_job_active_record (4.0.1)
  * diff-lcs (1.2.5)
  * dotenv (0.7.0)
  * erubis (2.7.0)
  * eventmachine (1.0.3)
  * exception_notification (4.0.1)
  * execjs (2.7.0)
  * extlib (0.9.16)
  * factory_girl (4.4.0)
  * factory_girl_rails (4.4.1)
  * faraday (0.9.0)
  * ffi (1.9.0)
  * ffi-compiler (0.1.3)
  * font_assets (0.1.11)
  * foreigner (1.6.1)
  * foreman (0.64.0)
  * formatador (0.2.4)
  * google-api-client (0.7.1)
  * grocer (0.5.0)
  * guard (2.6.0)
  * guard-rspec (4.2.8)
  * haml (4.0.5)
  * haml-rails (0.4)
  * heroku-rglpk (0.2.1 760859c)
  * hike (1.2.3)
  * i18n (0.9.5)
  * jmespath (1.4.0)
  * jquery-rails (3.1.0)
  * jquery-ui-rails (4.2.1)
  * json (1.8.6)
  * jwt (0.1.11)
  * launchy (2.4.2)
  * listen (2.7.1)
  * lumberjack (1.0.5)
  * mail (2.5.5)
  * memcachier (0.0.2)
  * method_source (0.8.2)
  * mime-types (1.25.1)
  * mini_portile (0.5.3)
  * minitest (4.7.5)
  * multi_json (1.13.1)
  * multipart-post (2.0.0)
  * newrelic_rpm (3.7.3.204)
  * nio4r (1.2.1)
  * nokogiri (1.6.1)
  * oauth (0.5.3)
  * orm_adapter (0.5.0)
  * paperclip (3.5.4)
  * pg (0.17.1)
  * pg_array_parser (0.0.9)
  * polyglot (0.3.5)
  * postgres_ext (3.0.1)
  * protected_attributes (1.0.3)
  * pry (0.9.12.6)
  * quiet_assets (1.0.2)
  * rack (1.5.5)
  * rack-cors (0.2.9)
  * rack-test (0.6.3)
  * rails (4.0.0)
  * rails_12factor (0.0.2)
  * rails_serve_static_assets (0.0.2)
  * rails_stdout_logging (0.0.3)
  * railties (4.0.0)
  * rake (12.3.2)
  * rb-fsevent (0.9.4)
  * rb-inotify (0.9.3)
  * request_store (1.0.5)
  * retriable (1.4.1)
  * rspec (2.14.1)
  * rspec-core (2.14.8)
  * rspec-expectations (2.14.5)
  * rspec-mocks (2.14.6)
  * rspec-rails (2.14.2)
  * rubyzip (1.1.7)
  * sass (3.4.25)
  * sass-rails (5.0.7)
  * scrypt (1.2.1)
  * shortener (0.3.0)
  * signet (0.5.0)
  * slop (3.5.0)
  * spork (0.9.2)
  * sprockets (2.12.5)
  * sprockets-rails (2.0.1)
  * strip_attributes (1.5.1)
  * thin (1.6.2)
  * thor (0.20.3)
  * thread_safe (0.3.6)
  * tilt (1.4.1)
  * timers (1.1.0)
  * treetop (1.4.15)
  * trim_blobs (0.0.1)
  * twilio-ruby (3.11.5)
  * tzinfo (0.3.55)
  * uglifier (2.5.0)
  * uuidtools (2.1.4)
  * xeroizer (2.16.5)
  * xpath (2.0.0)
  * yui-compressor (0.12.0)

This is what I get when I use pry:

[1] pry(#<BootstrapFormBuilder>)> options
=> {:class=>"span12"}
[2] pry(#<BootstrapFormBuilder>)> options[:autocomplete]
=> nil
[3] pry(#<BootstrapFormBuilder>)> options[:autocomplete] ||= 'off'
=> "off"
[4] pry(#<BootstrapFormBuilder>)> options.class
=> Hash
[5] pry(#<BootstrapFormBuilder>)> :autocomplete
=> :autocomplete
[6] pry(#<BootstrapFormBuilder>)> :autocomplete.class
=> Symbol
[7] pry(#<BootstrapFormBuilder>)> autocomplete
NameError: undefined local variable or method `autocomplete' for #<BootstrapFormBuilder:0x007ffe1030c878>
from (pry):7:in `text_field'
[8] pry(#<BootstrapFormBuilder>)> options[:autocomplete].clas
NoMethodError: undefined method `clas' for "off":String
from (pry):8:in `text_field'
[9] pry(#<BootstrapFormBuilder>)> options[:autocomplete].class
=> String

标签: ruby-on-railsrubyruby-on-rails-4rubygems

解决方案


推荐阅读