Skip to content

Instantly share code, notes, and snippets.

View pedromschmitt's full-sized avatar
🎲

Pedro Schmitt pedromschmitt

🎲
View GitHub Profile

Integration of TinyMCE in Rails 7 with Turbo Drive Support

Since Rails 7 the turbo-rails library is included by default. Turbo Drive intercepts link clicks and form submits. It makes sure that only the <body> part of the page is rerendered instead of the whole page.

This leads to TinyMCE not being properly detached and reattached when a Turbo Drive response is rendered. The textarea will appear without the TinyMCE editor. In this post we expand on the tinymce-rails gem with a Stimulus controller to prevent this issue. The controller helps to reattach TinyMCE and respects the settings in config/tinymce.yml.

If you want to follow along or check out the end result you can find an example respository here: https://github.com/david-uhlig/example-tinymce-rails7-turbo

Instructions

@pedromschmitt
pedromschmitt / linux-setup.sh
Created June 4, 2024 21:36 — forked from dhh/linux-setup.sh
linux-setup.sh
# Libraries and infrastructure
sudo apt update -y
sudo apt install -y \
docker.io docker-buildx \
build-essential pkg-config autoconf bison rustc cargo clang \
libssl-dev libreadline-dev zlib1g-dev libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev libjemalloc2 \
libvips imagemagick libmagickwand-dev mupdf mupdf-tools \
redis-tools sqlite3 libsqlite3-0 libmysqlclient-dev \
rbenv apache2-utils
@pedromschmitt
pedromschmitt / cookie_banner.md
Last active May 1, 2021 16:01
Adicionar banner de consentimento de uso de cookies no Rails
@pedromschmitt
pedromschmitt / 20201212155155_create_editor_assets.rb
Last active December 14, 2020 18:22
Manual Image Upload to Rails 6, TinyMCE 5 and Carrierwave (WITHOUT using gem 'tinymce-rails-imageupload', because it not support TinyMCE 5 yet)
# db/migrate/20201212155155_create_editor_assets.rb#
# generate with >> rails g model image alt:string hint:string file:string
class CreateEditorAssets < ActiveRecord::Migration[6.0]
 def change
 create_table :editor_assets do |t|
 t.string :alt
 t.string :hint
 t.string :file
 t.timestamps
@pedromschmitt
pedromschmitt / rails http status codes
Created November 29, 2020 12:26 — forked from mlanett/rails http status codes
HTTP status code symbols for Rails
HTTP status code symbols for Rails
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings.
Status Code Symbol
1xx Informational
100 :continue
101 :switching_protocols
102 :processing
<!--Select one Tag from many associations:-->
<div >
<label class="form-label">Tags</label>
<%= f.collection_select(:tags_id_eq, @tags, :id, :title, { include_blank: true}, { class: 'form-control', onchange: "this.form.submit();" }) %>
</div>
<!-- Check box for all tags -->
<div>
<label class="form-label">Tags</label>
<ul>
@pedromschmitt
pedromschmitt / conf-server-and-deploy-rails.md
Last active November 21, 2023 21:42
Setting up a new server and deploy Ruby

Setting up a new server and deploy Ruby on Rails project with Capistrano on VPS (Digital Ocean/Hetzner/etc)

This use Rails 5 or 6, RVM and Puma.

If you want to deploy with RBenv and Passenger, take a look at Phyl Smy script https://github.com/philsmy/cable-guy-example/blob/main/SetUpServer.txt and his video where he recorded each step https://www.youtube.com/watch?v=CZtYDplotiI&t=1s

If you need to deploy to a EC2 on AWS, check this video of how to create the server first: https://www.youtube.com/watch?v=M0avxObh8J8

Script

Dependencies

@pedromschmitt
pedromschmitt / img_convert.rb
Last active February 27, 2019 10:39 — forked from arirusso/img_convert.rb
convert html img tags to rails image_tag calls
#!/usr/bin/env ruby
require "nokogiri"
# opens every file in the given dir tree and converts any html img tags to rails image_tag calls
#
# example usage:
# ruby convert.rb ~/my_rails_app/app/views
#
# ***be careful and backup before using this***
#