我是Ruby on Rails的新手,这是我尝试的第一个项目。我安装了Rails,并进入屏幕,让我知道我已经成功安装了Rails。Rails Page
我运行rails g controller home index
创建了我的第一个网页,它成功完成并显示如下:
user@Ubuntu:~/dev/app$ rails g controller home index
Running via Spring preloader in process 183578
create app/controllers/home_controller.rb
route get 'home/index'
invoke erb
create app/views/home
create app/views/home/index.html.erb
invoke test_unit
create test/controllers/home_controller_test.rb
invoke helper
create app/helpers/home_helper.rb
invoke test_unit
invoke assets
invoke scss
create app/assets/stylesheets/home.scss
我尝试访问该页面,但它给了我这个错误:
Webpacker can't find application.js in /home/user/dev/app/public/packs/manifest.json. Possible causes:
1. You want to set webpacker.yml value of compile to true for your environment
unless you are using the `webpack -w` or the webpack-dev-server.
2. webpack has not yet re-run to reflect updates.
3. You have misconfigured Webpacker's config/webpacker.yml file.
4. Your webpack configuration is not creating a manifest.
Your manifest contains:
{
}
我尝试将webpacker.yml中的cache_manifest: false
和extract_css: false
更改为true
,但似乎没有帮助。我觉得webpacker安装不正确,所以我运行rails webpacker:install
。它失败了,并且从未成功完成:
`user@Ubuntu:~/dev/app$ bundle exec rails webpacker:install
conflict config/webpacker.yml
Overwrite /home/user/dev/app/config/webpacker.yml? (enter "h" for help) [Ynaqdhm] n
skip config/webpacker.yml
Copying webpack core config
exist config/webpack
identical config/webpack/development.js
identical config/webpack/environment.js
identical config/webpack/production.js
identical config/webpack/test.js
Copying postcss.config.js to app root directory
identical postcss.config.js
Copying babel.config.js to app root directory
identical babel.config.js
Copying .browserslistrc to app root directory
identical .browserslistrc
rails aborted!
NoMethodError: undefined method `exists?' for Dir:Class
/home/user/dev/app/bin/rails:5:in `<top (required)>'
/home/user/dev/app/bin/spring:10:in `require'
/home/user/dev/app/bin/spring:10:in `block in <top (required)>'
/home/user/dev/app/bin/spring:7:in `<top (required)>'
Tasks: TOP => app:template`
知道如何解决这个问题吗?这个错误太普遍了,我在搜索答案时遇到了麻烦。
轨道中止!
无方法错误:Dir:Class的未定义方法“exists?"
环境:Ubuntu 22.04 LTS台式机|导轨版本:6.1.7|Ruby版本:3.2.0
1条答案
按热度按时间pxy2qtax1#
我把我的Rails版本升级到了7,Ruby版本升级到了3.0.5,这样就可以绕过webpacker的问题了。问题似乎是Rails版本和我使用的Ruby版本之间不兼容。This是一个表,列出了每个Rails版本的推荐Ruby版本。
https://www.fastruby.io/blog/ruby/rails/versions/compatibility-table.html