Skip to content

Instantly share code, notes, and snippets.

@Matho
Last active June 7, 2023 19:12
Show Gist options
  • Save Matho/3587bd01c14f0e0bf60bf4bca3b733ec to your computer and use it in GitHub Desktop.
Save Matho/3587bd01c14f0e0bf60bf4bca3b733ec to your computer and use it in GitHub Desktop.
Refinery CMS with Rails 6.1.4 and Ruby 2.7.3 / Ruby 3.0.2

Hi

Here are instructions, how to be able run edge Refinery CMS with Rails 6.1.4 and Ruby 2.7.3 / Ruby 3.0.2

Refinery CMS with Ruby 2.7.3 and Rails 6.1.4

If you use rvmrc, like me, create gemset for Ruby 2.7.3

$ vim .rvmrc 
rvm use ruby-2.7.3@refinerycms-sample4 --create 

If you use Rbenv, you can specify the new ruby 2.7.3 in file .ruby-version

Install latest Rails gem

$ gem install rails -v=6.1.4  
$ gem install execjs

Install Refinery CMS from edge template (from Github master branch)

$ rails new rickrockstar -m https://www.refinerycms.com/t/edge

There is issue with Zeitwerk and Refinery CMS, so disable it until it is fixed (See refinery/refinerycms#3466 (comment) for the current status

$ vim config/application.rb
# append this line:
config.autoloader = :classic

If you rerun the rails new command again and you are stucked, disable Spring:

$ cd rickrockstar
$ spring stop
$ cd ..

Rerun installation, this time it should continue

$ rails new rickrockstar -m https://www.refinerycms.com/t/edge

There is another error, this time it incorrectly generate template for Gemfile file. Open Gemfile and fix the syntax, the gem with problem should be writen as gem 'sqlite3', '~> 1.4'

Rerun the command again, type 'n' to dont override the files again

$ rails new rickrockstar -m https://www.refinerycms.com/t/edge

There is some issue with routing-filter, so open Gemfile and insert:

gem 'routing-filter' , git: 'https://github.com/svenfuchs/routing-filter.git'

Install gems

$ cd rickrockstar
$ bundle update routing-filter

Rerun the command again, type 'n' to dont override the files again

$ rails new rickrockstar -m https://www.refinerycms.com/t/edge

If everything works, start the app and you should see the Refinery page located at http://localhost:3000/refinery

Refinery CMS with Ruby 3.0.2 and Rails 6.1.4

Before the following steps, I have executed the steps for installing Ruby 2.7.3

If you are using rvmrc, install Ruby 3.0.2

$ rvm install "ruby-3.0.2"

Change the Ruby version in .rvmrc file:

$ rvm use ruby-3.0.2@refinerycms-sample5 --create 

Open Gemfile and replace the Ruby version:

ruby '3.0.2'

Install gems for Ruby 3.0.2

$ bundle install

Because there are some syntax changes, you ned to clone Refinery CMS and fix it on your end, for now. This are my notes how to fix the issues to be able start the project. This steps are not the recommended way how to upgrade to latest Ruby.

Clone the Refinery CMS project:

$ cd ..
$ git clone https://github.com/refinery/refinerycms.git

Upgrade dependency path in Gemfile to:

gem 'refinerycms', path: '../refinerycms'

This will ensure, that you can do changes in the ../refinerycms folder path.

Open file refinerycms/core/app/helpers/refinery/translation_helper.rb There is method def t(key, options = {})

Change the argument to:

def t(key, **options)

Another issue is in refinerycms/core/app/helpers/refinery/site_bar_helper.rb Change site_bar_translate_locale_args to **site_bar_translate_locale_args

If you want to see changes, you should restart Puma server.

Open refinerycms/core/app/views/refinery/_site_bar.html.erb and find again the site_bar_translate_locale_args. Rewrite it to **site_bar_translate_locale_args

Also, there are issues with seo_meta gem. Clone the seo_meta project, change the dependency path in the Gemfile and open the file seo_meta/lib/seo_meta.rb You should see has_one :seo_meta, proc { where(:seo_meta_type => self.name) }, has_one_options . Rewrite has_one_options to **has_one_options

At the end of file, you should see fields << {:to => :seo_meta}. Comment or delete this line. Rewrite the delegate to delegate *fields, to: :seo_meta

Then, seems that we need to upgrade Mobility gem. But I'm not sure about it. Open refinerycms/pages/refinerycms-pages.gemspec and update the version of friendly_id-mobility: s.add_dependency 'friendly_id-mobility', '~> 1.0.3'

Clone git repo refinerycms-i18n and change the path in Gemfile. We will need to upgrade Mobility gem version there. So open refinerycms-i18n.gemspec and change version to s.add_dependency 'mobility', '~> 1.1.2' You can see more info about upgrade to new major version here https://github.com/shioyama/mobility/wiki/Introduction-to-Mobility-v1.0 Then, we need to change configuration for Mobility. Open refinerycms/core/lib/refinery/core/engine.rb . You should see old syntax, something like this:

Mobility.configure do |config|
  config.default_backend = :table
  config.accessor_method = :translates
  config.query_method    = :i18n
  config.default_options[:dirty] = true
end

We will replace it with the new syntax:

Mobility.configure do
  plugins do
    backend :table   # default_options[:type] is a backend option, so it must be passed to the `backend` plugin

    reader                             # Explicitly declare readers,
    writer                             # writers, and
    backend_reader                     # backend reader (post.title_backend, etc).

    active_record                      # You must now also explicitly ask for ActiveRecord (or Sequel)

    query                              # i18n is the default scope
    cache                              # previously implicit
    fallbacks
    presence                           # previously implicit
    default                            # previously implicit
    dirty
    fallthrough_accessors
    # attribute_methods                # uncomment this to get methods like `translated_attributes`
  end
end

I'm not sure, if all provided options are required.

Then we will install postgres gem (optional step). Open Gemfile and add:

gem 'pg'

Install dependency

bundle install

After that, we still have some issues after Mobility upgrade. Open refinerycms/pages/lib/refinery/pages/finder.rb and find method def translated_attributes I dont know how to fix this, so I'm using this workaround. I expect, that we should provide here all db table columns, we want to translate. Not sure.

def translated_attributes
  # Page.translated_attribute_names.map(&:to_s) | %w(locale)
  ['locale']
end

Last one, there is error in refinerycms/pages/app/presenters/refinery/pages/menu_presenter.rb . Change URI.decode to CGI.unescape, e.g. [path, CGI.unescape(path)].include?(url) || path == "/#{item.original_id}"

If everything works, start the app and you should see the Refinery page located at http://localhost:3000/refinery

-- (created 12th July 2021)

@dgm
Copy link

dgm commented Jun 7, 2023

Thank you for this... cross reference with https://github.com/refinery/refinerycms/pull/3518/files

The fix for translated_attributes in that PR is [*Page.mobility_attributes, 'locale'] but I too don't know if that is correct.

I wish this all would get pulled into the main repositories, ruby 2.7 is officially EOL which means there is no official running RefineryCMS on supported versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment