Skip to content

Instantly share code, notes, and snippets.

@ArturLyapin
Last active June 15, 2017 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArturLyapin/62669b79a0ab3a57ad2f563644f8e9e4 to your computer and use it in GitHub Desktop.
Save ArturLyapin/62669b79a0ab3a57ad2f563644f8e9e4 to your computer and use it in GitHub Desktop.
Mobility: Invalid single-table inheritance type issue
#app/models/member/first.rb
class Member::First < Member
end
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
gem 'rails', '~> 5.0.2'
gem 'pg', '~> 0.18'
gem 'mobility', '~> 0.1.16'
group :development do
gem 'listen', '~> 3.0.5'
end
#config/initializers/i18n.rb
Rails.application.config.i18n.available_locales = %i[en fi]
Rails.application.config.i18n.default_locale = 'en'
#app/models/member.rb
class Member < ApplicationRecord
include Mobility
translates :name, type: :string
end
#config/initializers/mobility.rb
Mobility.configure do |config|
config.default_backend = :column
end
#Run in rails console
-> Member.create!(type: Member::First.name)
ActiveRecord::SubclassNotFound: Invalid single-table inheritance type: Member::First is not a subclass of Member
ActiveRecord::Schema.define(version: 20170615120021) do
create_table "members", force: :cascade do |t|
t.string "type"
t.string "name_en"
t.string "name_fi"
end
end
#app/models/member/second.rb
class Member::Second < Member
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment