Rails 6.0 is scheduled to be release in the coming months. This posts explores what is new in Rails 6.0 and references to what needs to be done to implement them in your project.
Rails 6.0.0 rc1 has been released. It will require Ruby 2.5.0 or above. So what’s new?
- Action Text for rich text content with Trix Editor.
- Action Mailbox for inbound email.
- Parallel Testing by default.
- New multi-db support.
- Zeitwork code loader
Lets explore each one shortly, and I’ll give you links on tutorials on each specific topic.
Action Text brings easy rich text editing to Rails. It introduces a
has_rich_text DSL in the model for a
text field and a form helper
form.rich_text_area to show the Trix rich text editor. Also, the field will be renderend in erb as rich text.
Steps to use
Lets say we have an
BlogPost model with
content:text fields. After setting up the migrations, you need to install Action Text.
bundle exec rails action_text:install
This will copy the ActionStorage and ActionText migrations to your Rails app migrations folder. It creates the tables
In the BlogPost model
# models/blog_post.rb class BlogPost < ApplicationRecord has_rich_text :content end
In the BlogPost new/edit form use the
rich_text_area form helper to show the Trix editor.
form_with is being used from Rails 5.1
<%= form_with(model: blog_post, local: true) do |form| %> <div class="field"> <%= form.label :title %> <%= form.text_field :title %> </div> <div class="field"> <%= form.label :content %> <%= form.rich_text_area :content %> </div> <div class="actions"> <%= form.submit %> </div> <% end %>
@blog_post.content directly in the view will show rich text.
Action Mailbox routes incoming emails to controller like ActionMailbox inherited classes and processes them. It ships with ingresses for Mailgun, Mandrill, Postmark and SendGrid. (Note: Amazon SES ingress has been removed) It also supports inbound email for exim, postfix and qmail.
Steps to use
Lets setup SendGrid to be used with ActionMailbox.
Add ActionMailbox ingress config to
# config/environments/production.rb config.action_mailbox.ingress = :sendgrid
Create a new password for access of ActionMailbox. Use
rails credentials:edit to add the ingress_password key in the file that opens up during
Note: This is not your Sendgrid password, its a password to protect your inbound email endpoint.
Then configure Sendgrid with the url:
/rails/action_mailbox/sendgrid/inbound_emails with the username:
actionmailbox and the password set above. For example if your application is served from
https://abc123.com SendGrid should be configured with the url:
Credits: Header Photo by Leon Bublitz on Unsplash.