0

I am trying to set up a key system in the application I'm building. I have a code that has this logic:

$('.key-test-button').on('click', function(){
    if ($('.key-test-input').val() === "MYKEYHERE"){
        $('#hidden-div-instructor').show();
    } 
});

And My Idea was to replace "MYKEYHERE" for a hidden value on my code that I would store as a environment variable. I know how to do that for APIs for example, inside rails, but Im not familiar how I could access this variable inside my javascript/jquery script. I would love if someone could give me a insight. Thanks you.

2
  • You will need to pass it into the page/js. You could use a .js.erb in the js file for the specific view you're dealing with. Commented Dec 19, 2015 at 18:54
  • @Thais good way to pass variables through html data attribute and then used in ur javascript Commented Dec 19, 2015 at 19:26

1 Answer 1

2

As @davidhoelzer mentioned, you can't do this with pure js (as far as I know)... you could, however, change the .js file to .js.erb and use ruby to access/manipulate your environment variable that way.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the help everyone.

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.