Ruby on rails array - no implicit conversion of symbol into integer

no implicit conversion of symbol into integer params
no implicit conversion of enumerator into integer
faker typeerror no implicit conversion of integer into hash
no implicit conversion of symbol into integer yaml
no implicit conversion of string into array
no implicit conversion of string into integer
chef no implicit conversion of string into integer
unexpected error error_class=typeerror error=no implicit conversion of symbol into integer

I made a table component using react js, which uses columns to display data (which works fine with other data). For example, column 1 would show the title, column 2 the year, and column 3 the format.

Here is an example of my JSON:

{"movies": [{"title": "Iron Man", "year": "2008", "format": "DVD"}, {"title": "Iron Man 2", "year": "2010", "format": "DVD"}, {"title": "Iron Man 3", "year": "2013", "format": "DVD"}]}

Here is my code to populate the table, but it does not seem to work:

@movieList = #Makes a call to my mock API to get list of movies
@movies = Array.new

@movieList.each do |item|
 @movie = Hash.new
 @movie[:column1] = item[:title]
 @movie[:column2] = item[:year]
 @movie[:column3] = item[:format]
 @movies << @movie
end

I need some advice to overcome a "no implicit conversion of symbol into integer error" I get. Could anyone offer some advice and point out where I am going wrong?

tl;dr

use @movieList["movies"].each

explanation

The issue here, is that you act as though your @movieList is ann array, when it is actually a hash (assuming @movieList is the JSON you showed).

each works on both arrays and hashes. However, when you use it on a hash, the block is passed |key, val|. Also, assigning block variables is optional. So, when you say @movieList.each do |item|, item is actually the top level key of the hash ("movies").

Strings such as "movies" respond to [] indexing with numbers. That's why you get the error no implicit conversion of symbol into integer ... because you pass a symbol to String#[] and it expects an integer.

Another way to write this code, that is more idiomatic, would be like so:

@movies = @movieList["movies"].map do |movie|
  {
    column1: movie["title"],
    column2: movie["year"],
    column3: movie["format"]
  }
end

GitHub is home to over 50 million developers working together to host Chap 6: no implicit conversion of Symbol into Integer #32 It seems that the events_response is responding with something else than an array, have you inspected it? @kurenn - I found this rails-api/active_model_serializers#491. Rails Tricky Error: No Implicit Conversion From Symbol to Integer Published Sep 29 th , 2013 In working with Ruby on the new Write.app API, I’ve come across a number of problems related to using it as a pure RESTful API server rather than a full web app with views.

try reassigning

@movieList = @movieList[:movies] this will solve your problem. You're trying to iterate a object instead of an array.

lemme know if it solves your problem.

I am working on making my Rails 4.2.0/Ruby 2.2.1 app ready for Rails 5/Ruby 2.2​.3 and *args) throwing TypeError: no implicit conversion of Symbol into Integer when passing a One of the param holds an Array of hashes as shown below: I need some advice to overcome a "no implicit conversion of symbol into integer error" I get. Could anyone offer some advice and point out where I am going wrong? ruby-on-rails arrays ruby

You need to loop movies using @movieList["movies"] as your JSON is a hash that has a key 'movies' and an array of movies as a value => {'movies': [{...},{...},...]}

As @max pleaner explained assigning block variables is optional, but when you use each on a hash(your JSON in this case) and provide only one block variable (instead of two refering to the keys and values of the hash), your key-value pairs are converted to two-element arrays inside the block where first element is the key and second one is the value of the pair.

Your item looks like this inside your each block - ['movies', [{movie1}, {movie2},..]], hence:

item[0] # 'movies'
item[1] # [{movie1}, {movie2},...]

As arrays expect indexing with integers and you supply symbol (item[:title]), you receive:

TypeError (no implicit conversion of Symbol into Integer)

ruby - No implicit conversion of symbol to integer for Sinatra file up. This happens because Hash access, Array access, and String access are all done using  in 'rand': no implicit conversion of range into integer (TypeError) from C:/ruby/ca.rb:29:in 'get_numbers' from C:/ruby/ca.rb:33:in '<main>' Best How To : I wish to share another way to look at the problem, have a look and see if you are able to understand it:

this happens in the array. Even though you explained it I still don't really understand. I'm in chapter 8 of Rails Tutorial and that is most of my exposure so far. TypeError: no implicit conversion of Integer into String Ruby won’t let you add the calories variable to the rest of the output, because it’s an integer. We can’t just change it to a string by putting quotes around it, because, again, the calorie data might be coming from somewhere we don’t control.

ruby -v: 2.3.0-preview2. Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, If you try to dig in an Array using a symbol or string, a TypeError TypeError: no implicit conversion of Symbol into Integer and one from richonrails: no implicit conversion of Symbol into Integer - wo How to create a Javascript stubbed object during R With ruby on rails and devise, how to create anoth How can I use order and find_each in neo4j.rb, Rai Set default value of date_field only if current va How to set upload image progress bar with Papercli

Rails Tricky Error: No Implicit Conversion From Symbol to Integer Published Sep 29th, 2013 In working with Ruby on the new Write.app API, I've … that our keys_attributes was being interpreted as an array and not a hash. TypeError: no implicit conversion of Symbol into Integer when calling strong params Hi all, I have a form like this which is getting one param (:rating), for my @review model, and another (:review_photos), for my review_photos model.