Paul Krill
Editor at Large

What’s new in Rails 5.1: Better JavaScript, for one

news
Feb 27, 20172 mins

Rails 5.1 allows developers to manage JavaScript dependencies with Facebook's Yarn package manager

railroad tracks merging
Credit: Thinkstock

Ruby on Rails, the veteran server-side web framework, is playing nice with JavaScript in an upgrade that has recently moved to a first beta release.

Rails 5.1 offers multiple improvements, including encryption, system tests, and managing JavaScript dependencies from NPM via Facebook’s new Yarn package manager.

By managing JavaScript dependencies through Yarn, users can depend on libraries like React via NPM. Assets are made available in a pipeline, and the binstub bin/yarn is used to add these dependencies. Developers working with version 5.1 also can compile JavaScript using the Webpack module bundler, via a Webpacker gem. But Rails 5.1 drops jQuery as a default dependency. With the rewrite of rails-ujs unobtrusive scripting adapter to use vanilla JavaScript, this dependency is no longer needed.

Rails 5.1 also features an encrypted secrets management capability. An encrypted secrets file is set up by using the bin/rails secrets:setup capability, which generates a master key to store outside the repository while enabling developers to commit production secrets.

For system tests, Rails 5.1 includes a wrapping of the Capybara Ruby library for application testing. It comes preconfigured for the Chrome browser and enhanced with failure screenshots. The parameterized mailers feature offers the option to call mailers with parameters available before an action is invoked. Rails 5.1 simplifies form creation by unifying two hierarchies, form_for and form_tag, with form_with. A directed routes function, meanwhile, enables declaration of programmatic routes that can use Ruby to perform functions depending on parameters.

“We’ve had a stormy, perhaps even contentious, relationship with JavaScript over the years. But that time is past,” said a bulletin on the 5.1.0 release authored by dhh, who is presumably Rails founder David Heinemeier Hansson. JavaScript, the bulletin emphasizes, has “improved immensely” in recent years with the advent of ECMAScript 6 and tools like Yarn and Webpack.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author