我是Ruby on Rails的新手,也许这是一个非常小的问题,但我在网上搜索了一个解决方案,他们都至少有2-3年的历史,他们描述了同样的事情.我看的所有教程和视频都说要用React的webpack创建一个新应用程序,使用:

rails new app_name --webpack=react -d=postgresql -T

大家都说,这个命令将在我的app/javascript文件夹下创建一个pack文件夹,如下所示:

    app/javascript:
  └── packs:
      └── application.js
      └── hello_react.jsx

这一切都没有发生.我没有打包文件夹.相反,我有以下几点:

    app/javascript:
  └── controllers:
      └── application.js
      └── hello_controller.js
      └── index.js

那么,我做错了什么?为什么我没有pack文件夹,如何将React与Ruby on Rails集成?

推荐答案

In Rails 7, webpacker has been replaced by import maps, so that's why any old rails/react tutorial won't work for this newer version.
If you're starting a new project and want to use the React framework, my suggestion is to simply search for up-to-date Rails/React tutorials, as there are already plenty of them.
In case it's a project upgrading to Rails 7 and you don't want to get rid of webpack, you might consider to migrate to jsbundling-rails or start using shakapacker, which it seems to be from now the official successor of webpacker.
In jsbundling-rails project, there's a comparison of both gems to help you decide. Finally, there's a webpacker -> jsbundling-rails guide and a webpacker -> shakapacker guide to help you with your transition when you have finally decided which one to use.

Ruby-on-rails相关问答推荐

ActiveAdmin:的呈现索引表在父级的显示页中有许多资源

Rails 创建自定义函数/方法以及存储位置

我如何在不在 gemfile 中的 rake 任务中要求 gem?

多行与内联块之间的不同行为

别名可能与不同模型的相同别名有许多关联?

Selenium chromedriver:无法从不可键入的键构造KeyEvent

如何在 Rails 中注释掉 ERB?

Restful Rails 编辑与更新

rails 3,简单数组的Kaminari分页

如何为 Rails SimpleForm Select 框设置默认 Select 值

Rails 4 Form: has_many through: checkboxes

如何使用失败try 次数使设计可锁定

Rails 4网站图标问题

Rails 3 SSL 路由从 https 重定向到 http

Ruby on Rails 基本概念总结

为什么 Ruby on Rails 使用 http://0.0.0.0:3000 而不是 http://localhost:3000?

停止 Rails 为视图和助手生成规范测试?

rake db:回滚不起作用?

我的 JavaScript 模式/实践很糟糕.我应该go 哪里寻求帮助?

设置EDITOR或BUNDLER_EDITOR环境变量