Copy and paste this code into your terminal
class Message < ApplicationRecord has_rich_text :content end
<%= form.label :content %> <%= form.rich_text_area :content %>
<%= @message.content %>
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!