Editmode Docs
Search…
Getting Started with Editmode for Rails
Install The Gem
1
gem 'editmode'
Copied!
Generate your config
1
rails generate editmode:config {project_id}
Copied!
Configure caching
We use the rails cache to store content. This means if you don't have caching enabled your app will run quite slow.
1
# Rails 5+
2
rake dev:cache
Copied!
Setting up cache expiration webhooks
When an editor makes changes inside the Content Hub, we need a way to let the Rails app know and expire the cache for that particular content. We use cache expiration webhooks for this. The rails gem comes pre-loaded with endpoints to receive and expire the cache, so all you have to do is configure your project settings to notify the app when content is updated.
Adding cache expiration endpoints in your project settings
One caveat is that this method obviously won’t work when working with content locally. To bring your local content in sync with remote changes on the Content Hub, you should enter Editmode and select “Clear Cache”.
Bringing local content up to date with remote changes.
We are using a method called delete_matched to purge your caches when a content gets updated, and this method isn’t supported in memcached. We highly recommend using redis_store or file_store.

Using Editmode in your Rails codebase

  • There is full documentation on all of the editmode gem's methods and settings here.
  • Our 2 minute explainer video below should help you understand the
    basics.
  • Then, to help you get kicked off, we've also added code snippets
    that you can repurpose for your app.
Video: Editmode For Rails - Basic Syntax (2 minutes)

Code Snippets

Using Editmode for transactional email content in Rails

Setup Step 1. Create a collection in Editmode with "From", "Subject" and "Body" fields
Setup Step 2. Add a chunk to the newly created collection.

Create a new mailer using the following code

1
class UserMailer < BaseMailer
2
def editmode_email(chunk_identifier,user,variables={})
3
4
# Variables allow us to use things like "Hey {{first_name}}!"
5
# inside the email copy.
6
7
user_variables = {
8
:email => user.email,
9
:first_name => user.first_name,
10
:last_name => user.last_name
11
}
12
13
# Also allow other variables to be specified when the method
14
# is triggered
15
variables = user_variables.merge(variables)
16
17
to = user.email
18
from = Editmode.e(chunk_identifier, 'From', :variables => variables)
19
subject = Editmode.e(chunk_identifier, 'Subject', :variables => variables)
20
body = Editmode.e(chunk_identifier, 'Body', :variables => variables)
21
22
email = mail(
23
content_type: 'text/html',
24
to: to,
25
from: from,
26
subject: subject,
27
body: body
28
)
29
end
30
end
Copied!

Congratulations! You can now trigger emails from Editmode with a single line of code!

1
# The first argument here can take either the chunk's identifier or its content key
2
UserMailer.editmode_email("welcome_email",user).deliver_later
Copied!
Last modified 7mo ago