Hi I starting to use Layout API. I’ve got some trouble at the start
uninitialized constant Adebeo::Customer::Layout::Document
module Adebeo::Customer
class Drawing
attr_accessor
def initialize()
bom = Adebeo::Customer::Bom.new
annotations = bom.get_annotations
@doc = Layout::Document.open("/Users/denisbolomier/Desktop/zertzert\ émail\ /zertzert\ émail\ .layout")
…
I don’t understand why.
When I’m copying and pasting this code inside the ruby console its working. Why Layout::Document is not reconize inside my class?
Thanks !
TIG
May 23, 2020, 2:30pm
2
You only gave us partial code.
In the very top of the RB file did you include
# encoding: UTF-8
to force the encoding correctly ?
I see your path includes accented characters = émail
1 Like
TIG:
encoding: UTF-8
Thanks TIG, its works!
I code hundred of ruby file and I never have this trouble before. Is it link to Layout ?
TIG
May 23, 2020, 3:03pm
4
You should always include that top line in your RB files.
It stops you accidentally using non-UTF-8 encoded strings in your code.
But if you are getting those strings brought in from ‘outside’ it’s also good practice to force the encoding of those strings to suit Ruby… e.g.
my_file_path = __FILE__.force_encoding("UTF-8")
Just in case perhaps the user’s AppData path is not initially encoding as you need…
denis_bolomier:
Is it link to Layout ?
NO. It is a Ruby coding paradigm. Denis, please read …
Within module nesting , you can also use the Ruby scope operator to signify top level. Simply precede the module or class identifier with a ::
to tell Ruby it is defined in the top level ObejctSpace. …
@doc = ::Layout::Document.open(
"/Users/denisbolomier/Desktop/zertzert\ émail\ /zertzert\ émail\ .layout"
)
1 Like
This example also nicely shows the analogy between the leading slash for global paths and leading :: for constant lookup.
I am not influent in coding and I get the same problem with Layout constant.
I got an error in console like this
So I’m sorry but can you show me how to add encoding: UTF-8 with # at first. Because it will be recognized as a comment.
TIG
July 31, 2021, 12:52pm
9
In reverse order…
Add this text to the very first line in your RB file
# encoding: UTF-8
Please post formatted clear code snippets, rather than clipped images etc, which don’t help us understand what you are doing…
2 Likes