[Rails5] Fix `Route source can't be blank`
In Rails 5.0 automatic inverse does not work for polymorphic relathionships. It was fixed in Rails 5.2: https://github.com/rails/rails/pull/28808 Until that the `inverse_of: :source` argument should be set explicitly.
This commit is contained in:
parent
35816eb7be
commit
c3e40ed8ff
|
@ -4,7 +4,9 @@ module Routable
|
|||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
has_one :route, as: :source, autosave: true, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
|
||||
# Remove `inverse_of: source` when upgraded to rails 5.2
|
||||
# See https://github.com/rails/rails/pull/28808
|
||||
has_one :route, as: :source, autosave: true, dependent: :destroy, inverse_of: :source # rubocop:disable Cop/ActiveRecordDependent
|
||||
has_many :redirect_routes, as: :source, autosave: true, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
|
||||
|
||||
validates :route, presence: true
|
||||
|
|
Loading…
Reference in New Issue