undefined method `[]' for nil:NilClass
says you tried to do something[index]
but something
is nil
. Ruby won’t let you use nil
as an array (ie. call the []
method on it).
The problem is not on the attributs.each
line but on the line following which calls the []
method on attribut
.
typeAttribut = attribut['objectTypeAttribute']
This indicates something in attributs
is nil. This could happen if attributsParam
is a list that contains nil like so.
attributsParam = [nil]; attributs = Array(attributsParam); # [nil] puts attributs.inspect
Simplest way to debug it is to add puts attributs.inspect
just before the loop.
Also consider if you really need the attributs = Array(attributsParam)
line or if it’s already something Enumerable.
Related Posts:
- What does %w(array) mean?
- Array to Hash Ruby
- How to map with index in Ruby?
- How to sum array of numbers in Ruby?
- Ruby array to string conversion
- How to check if a value exists in an array in Ruby
- What is the “right” way to iterate through an array in Ruby?
- Difference between map and collect in Ruby?
- Creating and iterating a 2d array in Ruby
- What is the best way to convert an array to a hash in Ruby
- How can I delete one element from an array by value
- How to add to an existing hash in Ruby
- Get underlined text with Markdown
- What is the meaning of *nix?
- Get underlined text with Markdown
- What does the “map” method do in Ruby?
- How to write a switch statement in Ruby
- Rails 5 ActionController::InvalidAuthenticityToken error
- what does ? ? mean in ruby
- How to update Ruby Version 2.0.0 to the latest version in Mac OSX Yosemite?
- How to use “gets” and “gets.chomp” in Ruby
- Getting a substring in Ruby by x number of chars
- How to check whether a string contains a substring in Ruby
- Ruby: How to install a specific version of a ruby gem?
- ruby operator “=~” [duplicate]
- What does << mean in Ruby?
- What is attr_accessor in Ruby?
- ActionController::UnknownFormat
- What does ||= (or-equals) mean in Ruby?
- How to read lines of a file in Ruby
- Ruby equivalent for Python’s “try”?
- What does “+=” (plus equals) mean?
- Rails 4 RoutingError: No Route Matches
- undefined method (NoMethodError) ruby
- Multi-Line Comments in Ruby?
- How to uninstall ruby installed by ruby-install
- PG::ConnectionBad – could not connect to server: Connection refused
- Rails syntax error : unexpected keyword_ensure, expecting end-of-input
- Removing all installed Gems and starting over
- Ruby `send` vs `call` method
- What is the meaning of “do | |” in Ruby?
- RVM is not a function, selecting rubies with ‘rvm use …’ will not work
- How to delete specific characters from a string in Ruby?
- Ruby: kind_of? vs. instance_of? vs. is_a?
- Rails: I installed Ruby, now “bundle install” doesn’t work
- How to do a newline in output
- Ruby: What is the easiest way to remove the first element from an array?
- Ruby String to Date Conversion
- p vs puts in Ruby
- Determining type of an object in ruby
- Fizz Buzz in Ruby for dummies
- How to Uninstall RVM? [duplicate]
- What is the difference between a Process’ pid, ppid, uid, euid, gid and egid?
- Equivalent of “continue” in Ruby
- What does the Ruby method ‘to_sym’ do?
- Array to Hash Ruby
- Hashing arrays in Python
- Ruby 2.0.0p0 IRB warning: “DL is deprecated, please use Fiddle”
- Getting error: dyld: Symbol not found: _clock_gettime
- Uninstall old versions of Ruby gems
- Uploading a file in Rails
- What is java interface equivalent in Ruby?
- Sort hash by key, return hash in Ruby
- Gem installation error: You have to install development tools first
- How to understand strptime vs. strftime
- How to break out from a ruby block?
- ERROR: While executing gem … (Gem::FilePermissionError)
- No such file or directory @ rb_sysopen ruby
- Ruby ‘require’ error: cannot load such file
- How to convert a string to lower or upper case in Ruby
- What is the canonical way to trim a string in Ruby without creating a new string?
- Difference between $stdout and STDOUT in Ruby
- No implicit conversion of String into Integer (TypeError)?
- Multi-Line Comments in Ruby?
- ValueError: operands could not be broadcast together with shapes (5,) (30,)
- How can I remove a specific item from an array?
- lvalue required as left operand of assignment – Array
- How to find list intersection?
- Does JavaScript have a method like “range()” to generate a range within the supplied bounds?
- Is arr.__len__() the preferred way to get the length of an array in Python?
- Python: slicing a multi-dimensional array
- Shuffle an array with python, randomize array item order with python
- Adding values to a C# array
- Get all unique values in a JavaScript array (remove duplicates)
- Make list of arrays in python
- Printing an array in C++?
- How to sort an array of objects in Java?
- HashSet vs. List performance
- Error: unsupported use of matrix or array for column indexing
- NullPointerExcetion Native Method Accessor… Hashing Words Issue
- C# Foreach statement does not contain public definition for GetEnumerator
- How to create a numpy array of lists?
- Checking for duplicate strings in JavaScript array
- What is a hash function in java?
- What does @@variable mean in Ruby?
- Counting array elements in Python
- sorting array in mips (assembly)
- C++ Array of pointers: delete or delete []?
- Java says this method has a constructor name
- What does arg mean in WordPress