rails: Default Rails 7 setup with CSS processor breaks rich_text
Steps to reproduce
Create a new project, using local Rails, with esbuild for javascript and Bootstrap for CSS, install Action Text and create a new model having rich_text
, migrate and start the server:
rails/railties/exe/rails new example-project --dev -j esbuild --css bootstrap && cd example-project && bin/rails action_text:install && rails g scaffold article title:string content:rich_text && rails db:migrate && ./bin/dev
Expected behavior
When going to http://127.0.0.1:3000/articles/new I would expect to be able to change my Article content, using the Trix editor, with properly having setup the styles that are compatible with my chosen CSS processor.
Actual behavior
The Trix editor seems broken, and only works when not using Bootstrap (or e.g. Bulma for that matter).
System configuration
Rails version:
Rails 7.0.0.alpha2
Ruby version:
ruby 3.0.0-p0
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 3
- Comments: 27 (3 by maintainers)
Commits related to this issue
- fix actiontext field render bug solution from: https://github.com/rails/rails/issues/43441#issuecomment-1019426236 BUG: old content not shown when editing post — committed to SichangHe/rails_forum by SichangHe 2 years ago
- fix actiontext field render bug solution from: https://github.com/rails/rails/issues/43441#issuecomment-1019426236 — committed to SichangHe/rails_forum by SichangHe 2 years ago
- fix: fixed problem in production: 404 for actiontext.css; solution: https://github.com/rails/rails/issues/43441 — committed to abnatal/railsblog by abnatal 2 years ago
- Fix rich text The styles were not loading as supposed to be. According to the [1], it only required to change the order of imports. [1]: https://github.com/rails/rails/issues/43441 — committed to ciupkajakub/shop by ciupkajakub a year ago
@simonsapiel I could do it by:
And I deleted import “actiontext.css” from application.tailwind.css
Seems to work almost perfect. When checking with Bootstrap it’s fine. But with tailwind it is not.
Why?
The file
app/assets/stylesheets/application.tailwind.css
is populated with the new@import "actiontext.css";
at the end, looking like this:and then it does not work. But when I change the file like this (moving the added line to the top):
This way it works (for me at least)! 🎉
So, apparently that line needs to be on top for Tailwind. But I’m not a CSS expert (and don’t know anything about ordering here). This is just what occurs to me. ¯_(ツ)_/¯
This worked for me:
Setup:
I faced this same issue and was able to resolve by simply running the build commands defined in
package.json
What really solved this issue for me is that I linked actiontext.css directly in application.html.erb.
I managed to fix the above shared image issue by running
rails css:build
and I’m not sure if it had any effect but I usually runrails javascript:build
along with the other just to be safe and it worked itself right out.I’ve added this
<%= javascript_importmap_tags %>
and it works correctly!Try to run
rails assets:precompile
, it maybe helps you finding the error!.Versions:
Really thanks for this answer it helped me a lot. Thanks Again.
@zahidalik thank you for this! I was able to use your method to make it work with vite and tailwind
rails assets:precompile
I was able to solve my rich text with that command, I am using Rails 7.0.2 and Bootstrap 5.1
I opened a PR to address this issue. I’m happy to hear any feedback you have on the implementation @rogiervandenberg.
ok. I’ll give it a try. 👍🏾