I have understood the process and I have applied t...
# avo-2
r
I have understood the process and I have applied to my app. I have some issue more 1. - I have app/javascript/js/my_custom.js 2. - In avo.custom.js, I have added
import './js/my_custom.js
3. - In browser sources tool I am able to see localhost:3000>assets>avo.custom-blahblah1234.js 4. - In this .js file I can see my custom functions
function my_function(){...}
but if in my custom new file
<script>my_fucntion()</script>
doesn't works. In fact, the console prints
Uncaught ReferenceError: my_function is not defined
Any idea?
l
it's the way browsers work
because we declared
defer: true
on the
<%= javascript_include_tag "avo.custom", "data-turbo-track": "reload", defer: true %>
tag, the browser will not load the content untile the page is loaded
that's for performance reasons
so, when the page is loaded, that function is not available for the browser to run
there are two ways of doing this:
1. (which I don't recommend) is to remove the
defer: true
tag. This way, the function will be available to the custom page but, then you'll be exposed to of performance issues and some other JS side-effects
2. wrap the function call in a load event like so
Copy code
js
<script>
  document.addEventListener('turbo:load', () => {
    my_function()
  })
</script>
depending on what you need to do, there's a third, preferred way
3. instead of calling JS inside the custom page, use a stimulus controller that will automatically
connect
to the DOM when the page is loaded
does that answer your question @ripe-article-50191 ?
r
I am going to test the 2 and 3 options, and I will let you now the results....
l
sounds good 👌
r
The option 2 works fine. Later I will try to use stimulus.
But now I have another issue.... after change AVO version Now when I go to any of my resources lists, I get a problem related to cypher and OpenSSL. I show you the screen:
ensure that you have one of the following.
ENV['SECRET_KEY_BASE']
,
Rails.application.credentials.secret_key_base
, or
Rails.application.secrets.secret_key_base
set
it must be a minimum of 32 characters
use
bin/rails secret
to generate a new secret and set it to the
env
or to the secrets
here's a more in-depth look into the security matters
r
My app has configurated the sercrets in config/secrets.yml with 3
secret_key_base: d40...
for development, test and production
Sorry, I cannot see config/master.key. This can be the problem. I am going to create a master.key and I will let you know the resultas
Dear Adrian. I have made tests and this is not the problem. I have regenerate a new config/credentials.yml.enc config/master.key config/secrets.yml
The problem persist. I am running the development in a docker container and the issue exists. If I run development localy on my Mac (without docker), the application works fine. May be a problem with openssl in the docker?
Any idea?
l
Hmm. It should work
Maybe the docker env can’t see the master key?
Have you made sure you restarted the docker environment? The rails server must be restarted in order to see the secrets change
r
Yes Adrian, I have restarted the docker
docker-compose up
But the stuff I can not undertand, it's if I call to
http://localhost:3000/en/avo/resources/projects/new
or
http://..../1/edit
the system works fine
The error only is produced in listing model
I have been checking inside the docker and master.key and secrets.yml exist in docker files
If I remove and build the docker again, can be it a solutions?
l
Hey Angel. I only now started work
Yes. Rebuikding the dicker image might fix it
I think it’s because you added files
Just to be clear, this is not an Avo issue. It’s how the project is structures
This is normal because only on the Index view, the secret is required
r
Adrian I have full remove the containers and images, and restore from zero the docker, and the problem on index view persist...
Adrian, any other idea? Sorry to insist but all my team is waiting for the deployment of the app, and this is my only issue...
l
again, I'm happy to help, but I'd like for you know that this isn't an Avo issue
try and output somewhere in your app
Rails.application.secrets.secret_key_base
or
Rails.application.credentials.secret_key_base
actually, better to output all three
[ENV['SECRET_KEY_BASE'], Rails.application.credentials.secret_key_base, Rails.application.secrets.secret_key_base].inspect
anywhere in the app
and see what that gives you
if all three are blank, it means that your app does not have access to any of them, thus, the encyrption can't work
does that make sense?
if any of them does have output, then, it might be an Avo issue
but going from this, it might be a problem with the docker setup
so please add this anywhere in your app, run it from docker and let me know if any of it has anything assigned (don't publish the actual key publicly here please)
r
OK, I go
All of them print a result. The text is one per line separated and text is the code separated, by ","
So I suppose... is the encryption working on the docker?
l
Yes
Are you available to jump on a call to triubleshoot together in 5 minutes?
r
Yes, no problem.
In 5 minutes
l
Cool. Let me ping you in a few minutes
r
Ok, thanks
l
I'm here when you're ready
[ENV['SECRET_KEY_BASE'], Rails.application.credentials.secret_key_base, Rails.application.secrets.secret_key_base].inspect
Adding here what happened on our call: we figured out that Angel's app had all three values set👆
but the
ENV['SECRET_KEY_BASE']
has a dummy value
foosecretkey
which is lower than 32 characters. that's why it was failing
so the resolve is to remove the
ENV['SECRET_KEY_BASE']
value so
Rails.application.secrets.secret_key_base
be available for the app
r
Adrian. I have been thinking about the issue during my lunch, and I have been illuminated. I have put in the docker-compose.yml, on the environment - SECRET_KEY_BASE=hfdhjdhfd The string that appears in the generated file config/master.key This string is 32 characters length. And "ohh my god" the cipher problem disappears and all the resources indexes work fine. I think that the issue is solved.
A lot of thanks for your help, and we will keep in contact for further issues
l
Anytime! I’m glad it all worked out.
7 Views