Search code examples
ruby-on-railsruby

URI Error with Ruby when trying to run an application


so for some reason my Ruby encounter this error when I try to create a new application on Windows 10:

rails aborted!
URI::InvalidURIError: bad URI(is not URI?): C:\\Ruby\\bin;C:\\sqlite;
C:/Users/Lies/demo42/Rakefile:6:in `<main>' <internal:C:/Ruby/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in `require'
\<internal:C:/Ruby/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb\>:38:in `require' bin/rails:4:in `\<main\>'
(See full trace by running task with --trace)
rails  turbo:install stimulus:install
rails aborted!
URI::InvalidURIError: bad URI(is not URI?): C:\\Ruby\\bin;C:\\sqlite;
C:/Users/Lies/demo42/Rakefile:6:in `<main>' <internal:C:/Ruby/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in `require'
\<internal:C:/Ruby/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb\>:38:in `require' bin/rails:4:in `\<main\>'
(See full trace by running task with --trace)

I've searched everywhere on Google and so far I've try reinstalling twice, changing the path varible to C:\ruby and adding it to path and DATABASE variable.

My ruby, rails is on the latest version.

So far running "rails new demo --minimal" is the only one that work in helping me creating the application but when I try to run the server it show this: localhost:3000 output

Has anyone encountered this and figure out how to fix? I asked my professor, and it also picked his brain trying to figure out.

database.yml

# SQLite. Versions 3.8.0 and up are supported. 
# gem install sqlite3 
# Ensure the SQLite 3 gem is defined in your Gemfile 
# gem "sqlite3" 
#
default: &default 
  adapter: sqlite3 
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 
  timeout: 5000
development: 
  <<: *default 
  database: db/development.sqlite3 
# Warning: The database defined as "test" will be erased and 
# re-generated from your development database when you run "rake". 
# Do not set this db to the same as development or production. 
test: 
  <<: *default 
  database: db/test.sqlite3 
production: 
  <<: *default 
  database: db/production.sqlite3

Edit: for future reader: Here is the DATABASE_URL_ env variable with two value of "C:\sqlite" and "C:\Ruby\bin" I encounter the problem again later on, but manage to fix it again by editing the 'Path' env varible to only containing ruby and git value.


Solution

  • Since you have DATABASE_URL env variable, Rails use it as priority database configuration and try to parse it. But its value is invalid. That's why you have error

    Instead of this use config/database.yml to store database settings and delete DATABASE_URL env variable

    Read more