Action Text

forked from Action Text

https://guides.rubyonrails.org/action_text_overview.html

Action Text brings rich text content and editing to Rails. It includes the Trix editor that handles everything from formatting to links to quotes to lists to embedded images and galleries. The rich text content generated by the Trix editor is saved in its own RichText model that's associated with any existing Active Record model in the application. Any embedded images (or other attachments) are automatically stored using Active Storage and associated with the included RichText model.
view wysiwyg form 1,120 2


Dave Kimura
Dave Kimura

Jun 02, 2020

Copy and paste this code into your terminal

# app/models/message.rb
class Message < ApplicationRecord
  has_rich_text :content
end

# app/views/messages/_form.html.erb
<%= form.label :content %>
<%= form.rich_text_area :content %>

# view
<%= @message.content %>

# controller
class MessagesController < ApplicationController
  def create
    message = Message.create! params.require(:message).permit(:title, :content)
    redirect_to message
  end
end

DISCLAIMER: You should always review templates before running them. By running the template, you are agreeing to the terms of use.

The contents of this script as show. Any updates will be reflected in the below code and the snippet.

def puts_yellow(heredoc)
  puts set_color heredoc, :yellow
end

def puts_green(heredoc)
  puts set_color heredoc, :green
end

if !defined?(Webpacker)
  puts_yellow 'Webpacker was not installed. Adding it now...'
  gem 'webpacker'
  rails_command 'webpacker:install'
end

rails_command 'action_text:install'
rails_command 'db:migrate'

puts_green <<~HEREDOC
Action Text is installed. Read the docs at https://guides.rubyonrails.org/action_text_overview.html

# app/models/message.rb
class Message < ApplicationRecord
  has_rich_text :content
end

# app/views/messages/_form.html.erb
<%= form.label :content %>
<%= form.rich_text_area :content %>

# view
<%= @message.content %>

# controller
class MessagesController < ApplicationController
  def create
    message = Message.create! params.require(:message).permit(:title, :content)
    redirect_to message
  end
end
HEREDOC

A place where you can thank the author, post problems, give constructive feedback, etc. Be nice!

  • ovi_tsb
    Hi, Dave just a small think: on safari some of template are not visible on hover.
    Please delete this comment after read it is not related of this template. 
    Nice day.
    by ovi_tsb at 3:03AM, 02 Jun 2020