refinerycms-news
refinerycms-news copied to clipboard
Db migrations fail with the refinery4-compatible branch matho-update
I installed this gem for my refinerycms 4.0.3 app (with Rails 5.1) from the matho-update branch:
gem 'refinerycms-news', github: 'refinery/refinerycms-news', branch: 'matho-update'
In general, it was a good experience. However, the first migration failed with a message:
== 20200915155938 CreateNewsItems: migrating ==================================
rails aborted!
StandardError: An error has occurred, all later migrations canceled:
[FriendlyId] You need to translate the 'slug' field with Mobility (add 'translates :slug' in your model 'Refinery::News::Item')
/usr/local/rvm/gems/ruby-2.5.7@refinery403/gems/friendly_id-mobility-0.5.4/lib/friendly_id/mobility.rb:35:in `advise_against_untranslated_model'
In fact the model already contains translates :slug
. I checked that by overriding the model first.
Anyway, I could run the migrations successfully after temporarily commenting out the function advise_against_untranslated_model
in the friendly_id gem.
First I thought the error is raised because the field slug
is not yet added to the table in this first migration, but only in a later migration. But it is not that simple. I rolled back all ten migrations, added the field slug
to the create table
statement of the first migration, and tried to migrate again. Still I got the same error.
BTW, in the rollback of the create table
migration, ::Refinery::UserPlugin
was not found, and also this gives an error (because delete_all does not take parameters):
::Refinery::Page.delete_all :link_url => "/news"
So I edited it to
::Refinery::Page.where(link_url: "/news").delete_all
The same error (You need to translate the 'slug' field with Mobility
) appeared again when I visited /refinery/news/items
on my site. The error went away when I edited this line in the refinery/news/item model:
friendly_id :title, :use => [:slugged, :mobility]
into this:
friendly_id :title, use: :slugged
I already use mobility anyway for translations. I did not find any documentation for using :mobility
like that with the friendly_id
command.