Last active
June 15, 2017 12:26
-
-
Save ArturLyapin/62669b79a0ab3a57ad2f563644f8e9e4 to your computer and use it in GitHub Desktop.
Mobility: Invalid single-table inheritance type issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#app/models/member/first.rb | |
class Member::First < Member | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#config/initializers/i18n.rb | |
Rails.application.config.i18n.available_locales = %i[en fi] | |
Rails.application.config.i18n.default_locale = 'en' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#app/models/member.rb | |
class Member < ApplicationRecord | |
include Mobility | |
translates :name, type: :string | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#config/initializers/mobility.rb | |
Mobility.configure do |config| | |
config.default_backend = :column | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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