sosodev / actiontext-static

MIT License
4 stars 0 forks source link

HowTo: add to your Rails config #2

Open sosodev opened 4 years ago

sosodev commented 4 years ago

@ajessee

Starting a new issue on the repo so we don't cluter the Rails issue with unnecessary comments.

Sorry the readme was a little unclear. In your config environments e.g. config/environments/production.rb (note that the individual environment configs will only be loaded for the environment) you'll need to add require 'actiontext/patch' at the top of the file and then add ActionText::Static.patch(config) inside of the config block.

ajessee commented 4 years ago

@sosodev Thanks! Trying it right now, and I'll delete my comments from the other thread as to not clutter it up.

ajessee commented 4 years ago

Hey @sosodev, I feel like I'm so close!

I'm able to embed the gist and save my post...

embed

But when I try to view it, I'm only getting the content that I've put in the partial at:

/Users/andre/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/actiontext-6.0.2.rc1/app/views/action_text/attachables/content_attachments

Here is what I've got in there: image

I've tried to have it be empty, or turn it into an erb, but I have no idea what variable the content is stored in.

How do I access the content to display it? I really appreciate any help!

P.S. This is the content that I'm attaching:

image

sosodev commented 4 years ago

Hi @ajessee , sorry for the slow response. Unfortunately this naive patch doesn't actually save the content of your attachment. It doesn't save the content because that would require more complex changes to the way ActionText actually works. ActionText tries to minify and rebuild your content later on.

So the only content that gets pulled for your attachment is the content in your partial. The easiest way to make the patch work for you would be creating a different partial for each gist you want to attach.

So something like views/action_text/attachables/content_attachments/_payload_gist.html with your iFrame in it and then specifying vnd.rubyonrails.payload_gist.html as your contentType when attaching would always render that specific gist.

Let me know if that makes sense. Also, it probably feels a bit hacky and that's because it is! :joy: But sometimes hacks get the job done without having to rework everything.

ajessee commented 4 years ago

Hi @sosodev - No worries at all - you're doing me a big favor by helping me with all this.

I appreciate the clarification, I had a hunch that the static part was a hint that I wouldn't be able to inject dynamic HTML.

I think I might try to use active storage to attach a file to my post record, and then in the action text content add an anchor element for the file (the gist html), and then when the page loads, I'll use javascript to append the file to the anchor element.

I really appreciate the time you took to help me out!