Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
¿Cómo usar una condición de rieles dentro de una función Javascript .slim?

En mi archivo .slim tengo un bloque de javascript que contiene una URL, esta URL debe diferir según el entorno en el que se represente (puesta en escena/producción, etc.). Esta es la primera vez que uso este formato, por lo que no estoy seguro de si lo que estoy tratando de hacer es lógicamente posible.

Mi objetivo es crear un operador ternario que verifique Rails Env, si es 'Producción' haga X, de lo contrario haga Y.

Código a continuación:

archivo.delgado

 javascript: function zopimChat() { window.zEmbed || function (e, t) { var n, o, d, i, s, a = [], r = document.createElement("iframe"); window.zESettings = { webWidget: { offset: { vertical: "85px" } } }; window.zEmbed = function () { a.push(arguments) }, window.zE = window.zE || window.zEmbed, r.src = "javascript:false", r.title = "", r.role = "presentation", (r.frameElement || r).style.cssText = "display: none", d = document.getElementsByTagName("script"), d = d[d.length - 1], d.parentNode.insertBefore(r, d), i = r.contentWindow, s = i.document; try { o = s } catch (c) { n = document.domain, r.src = 'javascript:var d=document.open();d.domain="' + n + '";void(0);', o = s } o.open()._l = function () { var o = this.createElement("script"); n && (this.domain = n), o.id = "js-iframe-async", o.src = e, this.t = +new Date, this.zendeskHost = t, this.zEQueue = a, this.body.appendChild(o) }, o.write('<body onload="document._l();">'), o.close() } # condition below ("https://assets.zendesk.com/embeddable_framework/main.js", Rails.env.production? "testwebsite.zendesk.com" : "testwebsite-staging.zendesk.com" ); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puedes usar la interpolación:

 javascript: const railsEnv = "#{Rails.env}";

https://rdoc.info/gems/slim/frames#text-interpolación

En tu caso:

 ("https://assets.zendesk.com/embeddable_framework/main.js", "#{Rails.env.production? ? "testwebsite.zendesk.com" : "testwebsite-staging.zendesk.com"}" );
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!