0

The following instructions as per these suggestions, tried alternatively

instructions = JSON.load(self.signature).map { |h| "line #{h['mx']},#{h['my']} #{h['lx']},#{h['ly']}" } * ' '

instructions = JSON.parse(self.signature).map { |h| "line #{h['mx'].to_i},#{h['my'].to_i} #{h['lx'].to_i},#{h['ly'].to_i}" } * ' '

generate the error no implicit conversion of Array into String

If I state in the console

as = '[{"lx":21,"ly":39,"mx":21,"my":38},{"lx":21,"ly":39,"mx":21,"my":39},{"lx":21,"ly":37,"mx":21,"my":"my":37},{"lx":21,"ly":35,"mx":21,"my":36},{"lx":22,"ly":35,"mx":21,"my":35},{"lx":23,"ly":35,"mx":22,"my":35},{"lx":28,"ly":35,"mx":23,"my":35},{"lx":32,"ly":35,"mx":28,"my":35},{"lx":37,"ly":36,"mx":32,"my":35},{"lx":42,"ly":40,"mx":37,"my":36},{"lx":46,"ly":44,"mx":42,"my":40},{"lx":49,"ly":49,"mx":46,"my":44},{"lx":51,"ly":51,"mx":49,"my":49},{"lx":52,"ly":53,"mx":51,"my":51},{"lx":53,"ly":54,"mx":52,"my":53},{"lx":54,"ly":54,"mx":53,"my":54},{"lx":55,"ly":54,"mx":54,"my":54},{"lx":58,"ly":48,"mx":55,"my":54},{"lx":62,"ly":39,"mx":58,"my":48},{"lx":68,"ly":26,"mx":62,"my":39},{"lx":71,"ly":19,"mx":68,"my":26},{"lx":74,"ly":13,"mx":71,"my":19},{"lx":76,"ly":10,"mx":74,"my":13},{"lx":77,"ly":10,"mx":76,"my":10},{"lx":78,"ly":10,"mx":77,"my":10},{"lx":82,"ly":17,"mx":78,"my":10},{"lx":86,"ly":26,"mx":82,"my":17},{"lx":89,"ly":33,"mx":86,"my":26},{"lx":92,"ly":40,"mx":89,"my":33},{"lx":95,"ly":46,"mx":92,"my":40},{"lx":97,"ly":49,"mx":95,"my":46},{"lx":98,"ly":49,"mx":97,"my":49},{"lx":99,"ly":49,"mx":98,"my":49},{"lx":101,"ly":47,"mx":99,"my":49},{"lx":103,"ly":42,"mx":101,"my":47},{"lx":106,"ly":38,"mx":103,"my":42},{"lx":108,"ly":35,"mx":106,"my":38},{"lx":109,"ly":32,"mx":108,"my":35},{"lx":110,"ly":31,"mx":109,"my":32},{"lx":111,"ly":31,"mx":110,"my":31},{"lx":114,"ly":31,"mx":111,"my":31},{"lx":117,"ly":34,"mx":114,"my":31},{"lx":120,"ly":37,"mx":117,"my":34},{"lx":123,"ly":40,"mx":120,"my":37},{"lx":126,"ly":42,"mx":123,"my":40},{"lx":128,"ly":43,"mx":126,"my":42},{"lx":130,"ly":43,"mx":128,"my":43},{"lx":131,"ly":43,"mx":130,"my":43},{"lx":132,"ly":43,"mx":131,"my":43},{"lx":134,"ly":41,"mx":132,"my":43},{"lx":134,"ly":40,"mx":134,"my":41},{"lx":135,"ly":40,"mx":134,"my":40},{"lx":136,"ly":40,"mx":135,"my":40},{"lx":139,"ly":40,"mx":136,"my":40},{"lx":142,"ly":40,"mx":139,"my":40},{"lx":146,"ly":42,"mx":142,"my":40},{"lx":152,"ly":45,"mx":146,"my":42},{"lx":156,"ly":45,"mx":152,"my":45},{"lx":159,"ly":46,"mx":156,"my":45},{"lx":162,"ly":46,"mx":159,"my":46},{"lx":164,"ly":46,"mx":162,"my":46},{"lx":165,"ly":46,"mx":164,"my":46},{"lx":166,"ly":46,"mx":165,"my":46},{"lx":167,"ly":46,"mx":166,"my":46},{"lx":167,"ly":45,"mx":167,"my":46},{"lx":167,"ly":44,"mx":167,"my":45},{"lx":167,"ly":43,"mx":167,"my":44},{"lx":167,"ly":41,"mx":167,"my":43},{"lx":167,"ly":39,"mx":167,"my":41},{"lx":167,"ly":38,"mx":167,"my":39},{"lx":167,"ly":37,"mx":167,"my":38},{"lx":168,"ly":38,"mx":167,"my":37},{"lx":169,"ly":40,"mx":168,"my":38},{"lx":170,"ly":40,"mx":169,"my":40}]'

I get the same error. How does this get righted?

edit a console output that puts self.signature:

   (0.1ms)  BEGIN
{"lx"=>37, "ly"=>141, "mx"=>37, "my"=>140}
{"lx"=>37, "ly"=>139, "mx"=>37, "my"=>141}
{"lx"=>41, "ly"=>121, "mx"=>37, "my"=>139}
{"lx"=>52, "ly"=>96, "mx"=>41, "my"=>121}
{"lx"=>70, "ly"=>66, "mx"=>52, "my"=>96}
{"lx"=>85, "ly"=>49, "mx"=>70, "my"=>66}
{"lx"=>95, "ly"=>39, "mx"=>85, "my"=>49}
{"lx"=>107, "ly"=>34, "mx"=>95, "my"=>39}
{"lx"=>112, "ly"=>34, "mx"=>107, "my"=>34}
{"lx"=>118, "ly"=>34, "mx"=>112, "my"=>34}
{"lx"=>122, "ly"=>39, "mx"=>118, "my"=>34}
{"lx"=>125, "ly"=>52, "mx"=>122, "my"=>39}
{"lx"=>130, "ly"=>71, "mx"=>125, "my"=>52}
{"lx"=>134, "ly"=>88, "mx"=>130, "my"=>71}
{"lx"=>140, "ly"=>101, "mx"=>134, "my"=>88}
{"lx"=>145, "ly"=>115, "mx"=>140, "my"=>101}
{"lx"=>147, "ly"=>120, "mx"=>145, "my"=>115}
{"lx"=>150, "ly"=>124, "mx"=>147, "my"=>120}
{"lx"=>151, "ly"=>125, "mx"=>150, "my"=>124}
{"lx"=>152, "ly"=>109, "mx"=>151, "my"=>125}
{"lx"=>157, "ly"=>86, "mx"=>152, "my"=>109}
{"lx"=>166, "ly"=>63, "mx"=>157, "my"=>86}
{"lx"=>174, "ly"=>51, "mx"=>166, "my"=>63}
{"lx"=>191, "ly"=>49, "mx"=>174, "my"=>51}
{"lx"=>227, "ly"=>79, "mx"=>191, "my"=>49}
{"lx"=>249, "ly"=>108, "mx"=>227, "my"=>79}
{"lx"=>275, "ly"=>140, "mx"=>249, "my"=>108}
{"lx"=>295, "ly"=>158, "mx"=>275, "my"=>140}
{"lx"=>312, "ly"=>168, "mx"=>295, "my"=>158}
{"lx"=>330, "ly"=>170, "mx"=>312, "my"=>168}
{"lx"=>336, "ly"=>150, "mx"=>330, "my"=>170}
{"lx"=>339, "ly"=>122, "mx"=>336, "my"=>150}
{"lx"=>339, "ly"=>109, "mx"=>339, "my"=>122}
{"lx"=>339, "ly"=>98, "mx"=>339, "my"=>109}
{"lx"=>339, "ly"=>92, "mx"=>339, "my"=>98}
{"lx"=>339, "ly"=>91, "mx"=>339, "my"=>92}
{"lx"=>341, "ly"=>91, "mx"=>339, "my"=>91}
{"lx"=>347, "ly"=>101, "mx"=>341, "my"=>91}
{"lx"=>353, "ly"=>110, "mx"=>347, "my"=>101}
{"lx"=>358, "ly"=>118, "mx"=>353, "my"=>110}
{"lx"=>361, "ly"=>126, "mx"=>358, "my"=>118}
{"lx"=>363, "ly"=>129, "mx"=>361, "my"=>126}
{"lx"=>363, "ly"=>130, "mx"=>363, "my"=>129}
   (0.2ms)  ROLLBACK
Completed 500 Internal Server Error in 16ms (ActiveRecord: 1.2ms)
5
  • Can you provide the self.signature? My guess is that some of the content in self.signature cannot be converted to a string because it is an array. Commented Apr 8, 2016 at 8:38
  • I'm guessing you'll get the same error if you do just JSON.load(self.signature), because self.signature is already parsed (it's an array, not a string). Try doing self.signature.map ... Commented Apr 8, 2016 at 8:55
  • @magni- the instruction already had JSON.load(self.signature).map shane changing to JSON.load(self.signature.map) the errore returned is undefined method empty?' for #<Enumerator:0x007f814a987038>` Commented Apr 8, 2016 at 9:15
  • I'm saying you don't need to load signature because it's already an array, based on what you posted. Commented Apr 8, 2016 at 9:17
  • something needs to be loaded, otherwise the statement returns empty... Commented Apr 8, 2016 at 11:16

1 Answer 1

1

You have a syntax error in your as variable

as = '[{"lx":21,"ly":39,"mx":21,"my":38},{"lx":21,"ly":39,"mx":21,"my":39},
{"lx":21,"ly":37,"mx":21,"my":"my":37}


"my":"my":37

EDIT

You can try this

self.signature.map { |h| "line #{h['mx'].to_i},#{h['my'].to_i} #{h['lx'].to_i},#{h['ly'].to_i}" } * ' '
Sign up to request clarification or add additional context in comments.

4 Comments

good eyes! However even after correcting this, the TypeError subsists
You are correct, I can replicate that. which implies that the instructions command is mishandling the self-signature, as outputted.
what you get as a result if you did self.signature.to_json ? or if you try self.signature.map { |h| "line #{h['mx'].to_i},#{h['my'].to_i} #{h['lx'].to_i},#{h['ly'].to_i}" } * ' ' ?
Yes, both these syntassi function. and overcome the TypeError, so that would be the proper answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.