Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to change the RAILS_DIRECT_UPLOADS_URL? #43

Closed
mech opened this issue Nov 8, 2021 · 8 comments
Closed

Is there a way to change the RAILS_DIRECT_UPLOADS_URL? #43

mech opened this issue Nov 8, 2021 · 8 comments

Comments

@mech
Copy link
Contributor

mech commented Nov 8, 2021

Hi,

Great Trix integration with React. Want to ask if there is a way to change the URL for RAILS_DIRECT_UPLOADS_URL since our Rails API server is on another host.

Regards

@abhaynikam
Copy link
Owner

@mech RAILS_DIRECT_UPLOADS_URL is a constant relative URL right now. I like the idea to send a prop to customize the URL. Do you want to work on it? We are about to release a new version of the gem. This would be a great addition 😊

@mech
Copy link
Contributor Author

mech commented Nov 8, 2021

Sure, let me try it 😀

@mech
Copy link
Contributor Author

mech commented Nov 8, 2021

Hi, I have made a pull request at #44

However, I want to ask you a question. When I drag a file to the Trix editor, it does not seems to react, is there any additional step to perform?

@abhaynikam
Copy link
Owner

However, I want to ask you a question. When I drag a file to the Trix editor, it does not seem to react, is there any additional step to perform?

Yeah. We need to add onAttachmentAdd listener and handle the file addition. In the case of Rails, importing @rails/actiontext adds listener here: https://github.com/rails/rails/blob/main/actiontext/app/javascript/actiontext/index.js

@mech
Copy link
Contributor Author

mech commented Nov 9, 2021

Tks for the info. Just for those looking into it. Here's what I did:

import Trix from "trix";
import { ReactTrixRTEInput } from "react-trix-rte";
import "@rails/actiontext";

At the Rails API end, need to do much more effort:

  1. Setup config.action_controller.default_url_options to combat the example.org issue
  2. skip_before_action :verify_authenticity_token for all ActiveStorage controller if you do not need CSRF
  3. Make use of _blob.html.erb if you want a downloadable PDF link

Looking forward to get the pull request merged 😀

@abhaynikam
Copy link
Owner

Thanks, @mech ❤️ . Yeah in the Rails application importing "@rails/actiontext"; is important. ActionText form builder also relies on the same to handle the document attach.

We are close on closing this issue. Thank you @mech for your contribution 😊

@mech
Copy link
Contributor Author

mech commented Nov 10, 2021

I saw your Rails contribution on this rails/rails#39113 did not receive anymore attention. I am wondering if I can do this at the config/application.rb instead?

config.after_initialize do
  ActionText::Attachments::TrixConversion.class_eval do
    def to_trix_attachment(content = trix_attachment_content)
      attributes = full_attributes.dup
      attributes["content"] = content if content
      attributes["url"] = Rails.application.routes.url_helpers.rails_blob_url(preview_image.blob, only_path: false) if previewable_attachable? && previewable?
      ActionText::TrixAttachment.from_attributes(attributes)
    end
  end
end

Will using class_eval be the right way to sort of address it ATM?

@abhaynikam
Copy link
Owner

Fixed in #44

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants