ruby-on-railsrubyrubygemsopen-urithor

Rails new command fails if -m template is applied: "NoMethodError: private method `open' called for URI:Module"


I have been bumping into this issue and could not find a way to fix it.

When I am creating new rails apps using templates, the generator fails on private method 'open' called for URI:Module (NoMethodError)

Either way rails new app_name -m any_template_url or bin/rails app:template LOCATION=http://example.com/template.rb would return the same failure.

This is the terminal print out:

/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/thor-1.2.1/lib/thor/actions.rb:226:in `apply': private method `open' called for URI:Module (NoMethodError)

from /.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-5.2.6/lib/rails/generators/app_base.rb:170:in `apply_rails_template'

from (eval):1:in `apply_rails_template'

for which I understand the issue take place when we try to open the path to the file to execute and when rails tries to apply the template

How do I fix this?


Solution

  • For Rails 5.2 is recommended to use ruby 2.5. Update your ruby ​​version ​​and try again.

    Reference: https://www.fastruby.io/blog/ruby/rails/versions/compatibility-table.html