2

I have a file called myjavascript.js.erb in my assets path. This is where I put all my project related javascript etc.

As I understand it, rails runs this file through the erb interpreter first and then loads the resulting JS file.

I have the following line in my file

console.log( "<%= root_path %>" );

I was hoping that this would log the root path of the project but unfortunately it seems to only get me

"/path to rails project omitted/app/assets/javascripts"

Surely this should point to the root of my project? Am I doing something wrong?

1 Answer 1

2

You can use

Rails.root

To get to the root path in Rails.

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

3 Comments

I see. What about the path to the index action of one of my controllers?
I think it would be "/users/index" or something. I'm not too certain about that at the moment. Might want to make a separate question for that. Does my post fully answer your first question?
It's okay to ask lots of questions on here. I may not have the answer to the other one, but I'm sure someone does :)

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.