Getting started

Installation

🎉 Once you have purchased a license for Maglev PRO, you will receive an email containing the license key needed to install the Maglev PRO gem, along with instructions for adding this gem to your application's Gemfile.

Your application DB must be created first with bundle exec rails db:create

Add this line to your application's Gemfile:

source "https://<your license key>@packages.nocoffee.fr/private" do
  gem "maglevcms-pro", require: 'maglev/pro'
end

gem 'maglevcms', '~> 1.7.3', require: false

Note: the license key is the one you got from the email you receive after the purchase. If you deleted the email, no worries, send us an email at contact@maglev.dev.

And then execute:

$ bundle install

Prepare your app

Execute once the Maglev PRO installation generator within the folder of your rails app and follow screen instructions.

To function properly, Maglev PRO needs to identify which of your Rails models will own a Maglev site, as this varies depending on your business. 👋 If you are unsure, we are here to help you figure it out.

$ bundle exec rails g maglev:install

Create a theme and a first section

Create a first theme

$ bundle exec rails g maglev:theme Simple

and a dummy section

$ bundle exec rails g maglev:section Dummy --theme=Simple --category=content

It's now time to run your Rails app server.

$ bundle exec rails s

Please visit http://localhost:3000/maglev/admin, you will see your new theme and section.

[OPTIONAL] Embed a default theme in your application

The maglev-hyperui-kit gem includes a library of marketing sections based on hyperui, a free open source tailwindcss components.

First, add the Maglev HyperUI kit gem to your Gemfile:

Gemfile
gem 'maglevcms-hyperui-kit', '~> 1.2.0', require: 'maglev/hyperui'

Then execute:

$ bundle install

Now, install the theme and assign an id to it (default in our example):

bundle exec rails g maglev:hyperui:install --theme=default

Create programmatically your first site

We'll assume that you want to offer a site for each instance of the Account model in your application. Remember that you have made the choice of the parent model during the installation.

We're now going to create a new Maglev site based on the Simple theme and link it to one of your accounts.

If you installed the MaglevCMS HyperUI kit theme from the previous chapter, you'll have to replace simple by defaultin the next statements.

Open your rails console

$ bundle exec rails c

And type the following lines of Ruby code

my_account = Account.first
site = Maglev::Pro::GenerateSite.call(siteable: my_account, theme_id: 'simple', name: 'My first site', locales: [{ label: 'English', prefix: 'en' }])

In the next steps, inside your Rails application, you'll have to call the Maglev::Pro::GenerateSite service from one of your controller action, a model callback or your own service.

In order to get the editor UI url, in the Rails console, type:

app.maglev.base_editor_url(site_handle: site.handle, host: 'localhost:3000', locale: 'en')

It will return an url similar to this one: http://localhost:3000/maglev/black-wildflower-1100/editor/en/index.

However, most of the time, you will need to generate this link within your main application. If your site is mounted on your Account model, you should write something like:

<% if account.maglev_site %>
  <%= link_to "Edit site", maglev.base_editor_url(site_handle: account.maglev_site.handle, locale: 'en') %>
<% end %>

Going further

Congratulations, you now have Maglev PRO up and running within your Rails application!

It's time to start writing the sections for your themes 💪🚀.

Please refer to the concepts and guides for more information.

Last updated