1

I have a project to move some JS code outside of rails into the public direcotry, but some of it has ruby code embedded, and depends on the values of the variables from the controllers to set some of its code. How can I move it out of the view and still maintain the same structure, or do I need to just rewrite the JS from scratch?

1 Answer 1

1

You could move the core JavaScript code out of the view, and modify it such that anything that is a ruby variable is now passed as an input. Then from your view pages, just call the externalized JS using ruby code to pass in input values.

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

1 Comment

OK thank you! I thought that might be my only option, but I was hoping I could call the external JS file and inside the JS file it would have the rails interpreter available to it so I wouldn't have to :)

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.