administrate icon indicating copy to clipboard operation
administrate copied to clipboard

Guidance for Action Text custom field gem

Open migu0 opened this issue 3 years ago • 4 comments

I wanted to create an open source custom field https://github.com/migu0/administrate-field-action_text based on thoughtbot's instructions here.

I can successfully load the field but the Trix editor doesn't show. Can you help me find out how to get this working? I might have some Trix or Actiontext Javascript or CSS missing? Where should I best load it?

Screen Shot 2022-07-05 at 7 49 33 pm

Here's a test app to replicate the error: https://github.com/migu0/testapp

Thank you!

migu0 avatar Jul 05 '22 09:07 migu0

Hello @migu0 - I was having a look at this, but it looks like you have yanked the gem? If you could update the repo so that it's buildable, I'll try have another look.

pablobm avatar Jul 21 '22 14:07 pablobm

One initial question is: is all the JS and CSS for Trix, etc loading? In other words: do you see any 404s for them in your Network tab?

pablobm avatar Jul 21 '22 14:07 pablobm

Hi @pablobm thank you for following up on this. I gave up on it and removed Administrate from the project to make it work as I'm not very good with JS. If it helps I can re upload the gem or you could get it directly from Github in case you think it's worthwhile pursuing. I don't see any 404s but the below Screen Shot 2022-07-25 at 8 06 11 pm Screen Shot 2022-07-25 at 8 05 59 pm Screen Shot 2022-07-25 at 8 05 54 pm .

migu0 avatar Jul 25 '22 10:07 migu0

Right. So those import lines for Trix and ActionText, did you add them yourself? As the error shows, it appears not to be transpiled, and the browser doesn't understand it.

This is a topic that confuses me too, and I need to research better how to do it properly across different versions of Rails and its ever-changing ways of handling assets. If it helps, currently I have a personal app where I load the assets as follows:

# config/initializers/administrate.rb
Administrate::Engine.add_stylesheet("admin/application")
// package.json, dependencies
// Not sure if this one is actually relevant, actually
    "@rails/webpacker": "^5.3.0",
# config/initializers/assets.rb
Rails.application.config.assets.precompile += ["admin/application.css"]
# app/assets/stylesheets/admin/application.css
/*
 *= require_tree .
 *= require_self
 */

Then my CSS is at app/assets/stylesheets/admin/. Your problem is with JS instead, but the solution might be similar.

If you have the chance to try, please let me know how it went.

pablobm avatar Jul 27 '22 09:07 pablobm

Hi Pablo, I had to give up on this due to time constraints and lack of understanding of the JS pipeline in Rails. I recommend we close this and I'll move the repo on my side to private. Thank you

migu0 avatar Aug 13 '22 01:08 migu0

No worries. Thank you for coming back to me :slightly_smiling_face:

pablobm avatar Aug 15 '22 03:08 pablobm