Getting started


Your application DB must be created first with bundle exec rails db:create
Add this line to your application's Gemfile:
$ gem 'maglev-cli', group: :development
And then execute:
$ bundle install
Or install it yourself as:
$ gem install maglev-cli

Prepare your app

Execute maglev setup within the folder of your rails app and follow screen instructions.
$ bundle exec maglev setup

Create a theme and a first section

Create a first theme
$ bundle exec maglev theme Simple
and a dummy section
$ bundle exec maglev section Dummy --theme=Simple --category=contents
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.

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.
Open your rails console
$ bundle exec rails c
And type the following lines of Ruby code
my_account = Account.first
site = 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.
Last modified 6mo ago