2

I'm working on a JavaScript function in a Rails 5 application on my localhost, so I open the Chrome debugger tools and add a breakpoint to the application.js file:

enter image description here

Now I make a change to the JS file and reload the page, and the breakpoint is gone from the Chrome debugger tools:

enter image description here

Presumably this is because Rails has changed the UID that it appends to the name of the application.js file (http://localhost:3000/assets/application.self-22a4471f17f42....js?body=1) and Chrome can't maintain the breakpoint.

Is there a setting in Rails to avoid this during development?

5
  • Why aren't you using debugger in your script? Commented May 28, 2018 at 17:19
  • thanks, I didn't know that was an option - I've always used breakpoints in the browser's dev tools. If you want to put that as an answer I'll accept it. Commented May 28, 2018 at 19:52
  • I thought there is a specific reason you're not using it Commented May 28, 2018 at 20:01
  • Only cos I'd never come across it before - the Debugging Rails page only talks about using byebug for Ruby code Commented May 28, 2018 at 20:06
  • byebug provides ruby equivalent for javacript's debugger functionality. I'd like to think the concept was taken from javascript, I could be wrong. :P Commented May 28, 2018 at 20:09

1 Answer 1

1

You can use debugger in your javascript code to create breakpoints.

Example:

function youFunction() {
  debugger;
  // do your magic
}

Also to address another thing, I think you can set precompilation of assets to false, if that's not an issue for you, in your config/environments/development.rb file.

Please take a look at all possible options here: http://guides.rubyonrails.org/configuring.html#configuring-assets

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

Comments

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.