# Quotation marks in Html - Id(variable) - working in Sketchup Ruby Code Editor

**URL:** <https://forums.sketchup.com/t/quotation-marks-in-html-id-variable-working-in-sketchup-ruby-code-editor/136791>\
**Category:** Ruby API\
**Created:** [September 21, 2020, 7:12am UTC](https://forums.sketchup.com/t/quotation-marks-in-html-id-variable-working-in-sketchup-ruby-code-editor/136791 "2020-09-21T07:12:02Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Geordie](https://avatars.discourse-cdn.com/v4/letter/g/46a35a/32.png) [@Geordie](https://forums.sketchup.com/u/Geordie)\
**Post date:** [September 21, 2020, 7:12am UTC](https://forums.sketchup.com/t/quotation-marks-in-html-id-variable-working-in-sketchup-ruby-code-editor/136791/1 "2020-09-21T07:12:02Z")

</div>

We are working in Sketchup, using its Ruby Code Editor and we are programming a UI::WebDialog using Html and JavaScript. We want to define _document.getElementById( **variable** ).innerHTML_ using a _ **variable** _. How would you add the **single quotation marks**?

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [September 21, 2020, 5:06pm UTC](https://forums.sketchup.com/t/quotation-marks-in-html-id-variable-working-in-sketchup-ruby-code-editor/136791/2 "2020-09-21T17:06:08Z")

</div>

(_Please **post** your Ruby questions in the [Ruby API](https://forums.sketchup.com/c/developers/ruby-api/13) subcategory._)

* * *

**Is the variable a Ruby or JavaScript reference ?**

**What single quotation marks ?**

… ie, we cannot read minds. 🙄

* * *

If Ruby, then you **must** use a double-quoted string in order to do interpolation.

[I explained this in the other topic thread.](https://forums.sketchup.com/t/html-dialog-box-to-set-and-get-information/136387/5)

```ruby
# Ruby

dlg.execute_script(
  %[document.getElementById("#{ruby_id}").innerHTML="#{ruby_value}";]
)

```

I again point you to the Ruby Core primer on String literals …

[https://ruby-doc.org/core-2.5.5/doc/syntax/literals\_rdoc.html#label-Strings](https://ruby-doc.org/core-2.5.5/doc/syntax/literals_rdoc.html#label-Strings)

* * *

If you are doing this within JavaScript, … (which I doubt because you said your are using a SketchUp Editor extension,) … you just use a string reference that holds string ID.

---

<div class="post-metadata">

**Author:** ![Neil\_Burkholder](https://avatars.discourse-cdn.com/v4/letter/n/f4b2a3/32.png) [@Neil\_Burkholder](https://forums.sketchup.com/u/Neil_Burkholder)\
**Post date:** [September 21, 2020, 5:27pm UTC](https://forums.sketchup.com/t/quotation-marks-in-html-id-variable-working-in-sketchup-ruby-code-editor/136791/3 "2020-09-21T17:27:22Z")

</div>

> [@Geordie](#):
>
> we are programming a UI::WebDialog

Unless you are targeting versions older than 2017 I would recomend switching to the newer UI:HtmlDialog.

> **[Class: UI::HtmlDialog](https://ruby.sketchup.com/UI/HtmlDialog.html)**
>
> The Ruby HtmlDialog class allows you to create and interact with HTML dialog boxes from Ruby.

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [September 21, 2020, 6:57pm UTC](https://forums.sketchup.com/t/quotation-marks-in-html-id-variable-working-in-sketchup-ruby-code-editor/136791/4 "2020-09-21T18:57:32Z")

</div>

… **and** when using [`UI::HtmlDialog`](https://ruby.sketchup.com/UI/HtmlDialog.html) it displays in a window using the Chrome Embedded Framework which allows using the Chrome DevTools as I showed in the [other topic, post 12](https://forums.sketchup.com/t/html-dialog-box-to-set-and-get-information/136387/12) …

> [@Html dialog box to set and get information](https://forums.sketchup.com/t/html-dialog-box-to-set-and-get-information/136387/12):
>
> The second error I saw, after the dialog opened, I opened the Chrome DevTools window (as I told you to,) and switched to the Console tab.
> 
> ![image](https://global.discourse-cdn.com/sketchup/original/3X/3/2/323a9d7d39adaeecdd130a1f59f35bbb7bb647db.png)

When testing your HTML dialog, just right-click on your dialog window, and choose “ **Show DevTools** ” …

![image](https://global.discourse-cdn.com/sketchup/original/3X/7/a/7ae493c9ed08f791b1676ef98b84ef5f600b64c0.png)

---

<div class="post-metadata">

**Author:** ![Geordie](https://avatars.discourse-cdn.com/v4/letter/g/46a35a/32.png) [@Geordie](https://forums.sketchup.com/u/Geordie)\
**Post date:** [September 22, 2020, 12:27am UTC](https://forums.sketchup.com/t/quotation-marks-in-html-id-variable-working-in-sketchup-ruby-code-editor/136791/5 "2020-09-22T00:27:31Z")

</div>

I’m still working in Ruby Code Editor, and the variable is a JavaScript reference. I’ve tried some published solutions for JavaScript but they don’t work here.

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [September 22, 2020, 12:56am UTC](https://forums.sketchup.com/t/quotation-marks-in-html-id-variable-working-in-sketchup-ruby-code-editor/136791/6 "2020-09-22T00:56:35Z")

</div>

> [@Geordie](#):
>
> I’m still working in Ruby Code Editor, …

That **isn’t** good for developing an extension. It’s only useful for playing around (learning) with one liners or small snippets that do concise tasks.

As said, it has been known to introduce problems. It **itself** is a html dialog, that sends commands and script text to Ruby, which evaluates it, and would then send command to your html dialog.

> [@Geordie](#):
>
> …, and the variable is a JavaScript reference.

Well if the JavaScript reference is a String, and it exists in the dialog’s JS, and it matches an ID given to one of the documents elements, … there should not be an issue. You do not used quotes around an object reference in any coding language.

So … from Ruby …

```ruby
dlg.execute_script(
  %[document.getElementById(js_var}).innerHTML="#{ruby_value}";]
)

```

There **IS a quirk** with JS’s `innerHTML=` and Ruby strings. There **cannot** be any newline characters at the end of **any** of the HTML text in the Ruby string. If there are, the JS `innerHTML=` method can fail (perhaps silently.)

Since **you do not have control** over the Ruby strings sent to your dialog, (ie the “Ruby Code Editor” has all the control,) you will not be able to overcome that barrier, **if it occurs**.

* * *

In my extensions, when I load the HTML from a file, (and I have this problem) … I use a `:chomp` option to remove newline characters. IE … (_a snippet from my code_) …

```ruby
      # Load the HTML for each listing line striping out newline characters.
      # We must do this because the JavaScript method call element.innerHTML=
      # within CEF fails if the HTML text contains embedded Ruby newlines:
      list_line = File.readlines(filepath, chomp: true).join('')

```

* * *

If you insist working in this way you’ll continue to run into problems. I don’t have any more time to deal with silly issues.

My **last** advice to you is to ditch that “Code Editor”, and get a **real** editor application like:

- [Notepad++](https://notepad-plus-plus.org/downloads/)
- [MS Visual Studio Code](https://code.visualstudio.com/download)

Then code like a real programmer codes in files, and load your files as an extension loads when SketchUp starts.

- [Class: SketchupExtension — SketchUp Ruby API Documentation](https://ruby.sketchup.com/SketchupExtension.html)

---

<div class="post-metadata">

**Author:** ![Geordie](https://avatars.discourse-cdn.com/v4/letter/g/46a35a/32.png) [@Geordie](https://forums.sketchup.com/u/Geordie)\
**Post date:** [September 22, 2020, 1:00am UTC](https://forums.sketchup.com/t/quotation-marks-in-html-id-variable-working-in-sketchup-ruby-code-editor/136791/7 "2020-09-22T01:00:33Z")

</div>

As in any language, the natural learning process begins by repeating the words of others to try to say what you want to say; wich is particulary difficult when it comes to programming in Ruby+JS. I borrowed a WebDialog old example and I have managed to display my arrays in my html window. At the moment I don’t have enough level to assimilate all the information from your posts, although they are there for when they can help in this learning process.

---

<div class="post-metadata">

**Author:** ![Geordie](https://avatars.discourse-cdn.com/v4/letter/g/46a35a/32.png) [@Geordie](https://forums.sketchup.com/u/Geordie)\
**Post date:** [September 23, 2020, 8:23am UTC](https://forums.sketchup.com/t/quotation-marks-in-html-id-variable-working-in-sketchup-ruby-code-editor/136791/8 "2020-09-23T08:23:22Z")

</div>

As I said, I’m a novice Ruby person who started to program in Ruby, using the Skup Oficial Code Editor, 2 months ago, with the intention of programing, basically working on object attributes and exchanging information with excel, where I usually work. I didn’t expect the problems with the Skup 'Oficial’Code Editor or the recomenation to use JS and Html to display information in a proper way, which implies added problems, mostly unsolved from years ago. This silly issues don’t occur when you have worked properly to offer people a way to program. So they are the unexpected Sketchup Developers silly issues that any novice has to deal with. I will be very grateful to get all these unexpected information in advance, or your understanding when I keep saying or doing things in a wrong way, just because I didn’t get that information. Following your recomendation, I sincerely don’t know how I should program from other editors and run the program over my model. Thanks in advance. I will understand if you leave the forum. They are opened questions.

---

<div class="post-metadata">

**Author:** ![Neil\_Burkholder](https://avatars.discourse-cdn.com/v4/letter/n/f4b2a3/32.png) [@Neil\_Burkholder](https://forums.sketchup.com/u/Neil_Burkholder)\
**Post date:** [September 23, 2020, 11:02am UTC](https://forums.sketchup.com/t/quotation-marks-in-html-id-variable-working-in-sketchup-ruby-code-editor/136791/9 "2020-09-23T11:02:16Z")

</div>

> [@Geordie](#):
>
> Following your recomendation, I sincerely don’t know how I should program from other editors…

Here are the steps. I recommend VS Code.

> **[VSCode Debugger Setup](https://github.com/SketchUp/sketchup-ruby-api-tutorials/wiki/VSCode-Debugger-Setup)**
>
> SketchUp Ruby API Tutorials and Examples. Contribute to SketchUp/sketchup-ruby-api-tutorials development by creating an account on GitHub.

Also (contrary to Dan’s advice), I find Ruby Console + to be quite useful. You still need to use the built in ruby console to get accurate error info. That is what Dan mentioned. I find Ruby Console +, to be really handy when doing quick testing. You can use the built in tool to easily get a reference to an object in the model.

[https://extensions.sketchup.com/extension/b3865233-5e84-4f7e-8342-517aca889225/ruby-console](https://extensions.sketchup.com/extension/b3865233-5e84-4f7e-8342-517aca889225/ruby-console)

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [September 23, 2020, 8:47pm UTC](https://forums.sketchup.com/t/quotation-marks-in-html-id-variable-working-in-sketchup-ruby-code-editor/136791/10 "2020-09-23T20:47:52Z")

</div>

> [@Geordie](#):
>
> … using the Skup Oficial Code Editor, …

`1.` The is **no such word** as “Skup”.

`2`. There is no “ **Official** ” SketchUp Code Editor.

Instead, there are several 3rd party extensions, that are implemented in a web html dialog.

> [@Geordie](#):
>
> This silly issues don’t occur when you have worked properly to offer people a way to program.

Unfortunately, the reality is that it is not Trimble’s responsibility to teach any kind of programming. Only to document their APIs.

I **personally** have spent many days and hours to compile lists of resources for novice SketchUp Ruby coders …

> [@Ruby Learning Resources \[WikiLists\]](https://forums.sketchup.com/t/ruby-learning-resources-wikilists/22861/):
>
> All seven of the lists below are set as wikis. card_index INDEX [notebook PRIMERS & GUIDES](http://forums.sketchup.com/t/ruby-learning-resources/22861/2)[books BOOKS](http://forums.sketchup.com/t/ruby-learning-resources/22861/3)[mortar_board TUTORIALS](http://forums.sketchup.com/t/ruby-learning-resources/22861/4)[card_box REFERENCE](http://forums.sketchup.com/t/ruby-learning-resources/22861/5)[clipboard TEMPLATES](http://forums.sketchup.com/t/ruby-learning-resources/22861/6)[newspaper NEWS](http://forums.sketchup.com/t/ruby-learning-resources/22861/7)[bulb IDEAS](http://forums.sketchup.com/t/ruby-learning-resources/22861/8)

The list has links to **free** downloadable books on Ruby programming, as well as links to online blog posts and tutorials, many are SketchUp specific.

There are also a plethora of tutorials on the web for HTML, CSS, and JavaScript.  
A forum is not really an adequate place to teach programming.

> [@Geordie](#):
>
> So they are the unexpected Sketchup Developers silly issues that any novice has to deal with. I will be very grateful to get all these unexpected information in advance, or your understanding when I keep saying or doing things in a wrong way, just because I didn’t get that information

I am sorry that there is no way that we can “pour” the coding knowledge into novice brains.

Any person’s ability to absorb and apply new coding knowledge will depend upon their current foundation of the person’s programming knowledge.

This is why Steve asked you right away in the other topic on web dialogs …

> [@Html dialog box to set and get information](https://forums.sketchup.com/t/html-dialog-box-to-set-and-get-information/136387/2):
>
> What is your background and programming ability? Are you fluent in Ruby, HTML, and javascript? Have you studied the SketchUp Ruby API docs and examples?

… but you never really gave a good answer. So we didn’t have any good idea of your ability level.

So this basically makes me feel as though I’ve **wasted** two days of my time, when it comes to specifically helping **you**.

**It is no one else’s responsibility but your own, to seek out and learn basic programming knowledge, so that when you ask questions, you are able to understand the answers.**

> [@Geordie](#):
>
> I will understand if you leave the forum.

I am **not** leaving. I am just not going to waste any more time giving advice that will not be used.

Hopefully other readers may find it useful.

---

<div class="post-metadata">

**Author:** ![Geordie](https://avatars.discourse-cdn.com/v4/letter/g/46a35a/32.png) [@Geordie](https://forums.sketchup.com/u/Geordie)\
**Post date:** [September 29, 2020, 10:57pm UTC](https://forums.sketchup.com/t/quotation-marks-in-html-id-variable-working-in-sketchup-ruby-code-editor/136791/11 "2020-09-29T22:57:30Z")

</div>

Sorry Dan,

\*\*_1. There is **no such word** as “Skup”_  
I used Skup as an abbreviation of Sketchup.  
\*\*_2. There is no “ **Official** ” SketchUp Code Editor._  
You are right, they are no “Official” SketchUp Code editors, but they are recommended extensions that do what they should do, considering what you can learn from [https://ruby.sketchup.com/](https://ruby.sketchup.com/) I thought they were the better way to start programming with Ruby. I must confess that I’m lost when I read Ruby’s articles outside of the SketchUp environment, or I find any sample Ruby code. I have verified that there are commands not working in any of the Sketchup Code Editors, without any reference in [https://ruby.sketchup.com/](https://ruby.sketchup.com/), so I avoid those commands and those websites. Nevertheless, I think it’s better to use extensions to run the code easily and facilitate my learning process.

I think it is offensive to use the adjective “silly” to refer to someone’s issue. That will keep beginners away from this forum. Nor are they such silly problems when they need such complex solutions. Therefore, it is understandable that these issues, not well resolved, appear repeatedly for many years in this forum. So, if something has to be silly, it should be that nobody notices it or nobody improves it.

Trimble’s responsibility? Offer easy ways to do easy things. I appreciate the capability to create dictionaries with your own attributes, create lists, … but it’s dificult to understand why you can’t show or work with all this information in an appropriate way. You shouldn’t need to leave ruby to do all these kinds of things. By doing this, you are exposing your code to errors, incompatibilities with browsers, … Thus, I have to settle for using the dynamic attribute dialog box, with no possibility to group my information, nor use drop-down windows. And, this is not an attack, this is an attempt to make a constructive contribution. I love Sketchup too.

I very much appreciate your Ruby Learning Resources and you can be certain I will read them as soon as I can. I don’t understand why you believe that you are wasting your time. I’d never worked with HTML, CSS, or JavaScript, and I’m a beginner with Ruby. Your posts have been at a very high level and they are not easy to follow when you haven’t achieved that level. So, if this is not really an adequate place to teach programming with such languages, it is advisable to postpone them until my Ruby’s learning process will finish.

I hope that you will not be offended, it was never my intention.
