Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access Rails settings (development.yml , test.yml etc.) #1895

Closed
rahulakurati opened this issue Jan 17, 2019 · 4 comments
Closed

Access Rails settings (development.yml , test.yml etc.) #1895

rahulakurati opened this issue Jan 17, 2019 · 4 comments

Comments

@rahulakurati
Copy link

How to access rails settings variable (from development.yml etc.) inside JavaScript?

@jakeNiemiec
Copy link
Member

You can put something like this (and more) in your <head>. (or anywhere, it just needs to be before any javascript_pack_tags)

<script>
  window.mySettingsVariable = <%== @my_settings_variable.to_json %>;
</script>

A more complecated, but just as valid way of doing this would be to use the DefinePlugin in your config/environment.js. Here is one example I found: #1304 (comment)

Note: Anyone who visits your site can access variables set on the window object. Be careful not to set any sensitive info.

@rahulakurati
Copy link
Author

Ya thats right. I'm afraid binding to a window object might have security consequences.

@jakeNiemiec
Copy link
Member

JavaScript is completely client-side, anything you expose to is will be available to your users (even if not assigned to window). JS should never come into contact with data that has security consequences.

@guillaumebriday
Copy link
Member

Can this issue be closed ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants