Skip to content

Commit

Permalink
Replace Hydra::Presenter#to_model delegation with self
Browse files Browse the repository at this point in the history
Beginning in `v3.5.1`, `SimpleForm::FormBuilder` calls `#to_model` (via
ActionView's `#convert_to_model`) in its initializer. This prevents
`Hydra::Presenter` inheritors from being used correctly when sent to the
form. Replacing the delegated method with one that returns `self` restores the
correct behavior to `SimpleForm::FormBuilder` and related view helpers.

Client code can still access the model by calling the `#model` accessor.

Fixes #139.
  • Loading branch information
Tom Johnson committed Mar 5, 2018
1 parent 78ea076 commit f523e17
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions app/presenters/hydra/presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ def initialize(object)
@model = object
end

delegate :to_key, :to_param, :to_model, :persisted?, :new_record?,
:[], :model_name, to: :model
delegate :to_key, :to_param, :persisted?, :new_record?, :[], :model_name, to: :model

##
# @return [#to_model] self
def to_model
self
end

module ClassMethods
def model_name
Expand All @@ -33,8 +38,8 @@ module Presenter
included do
class_attribute :_terms, instance_accessor: false

# You may want to set your own field_metadata_service that can
# answer the questions about a fields cardinality regardless of the
# You may want to set your own field_metadata_service that can
# answer the questions about a fields cardinality regardless of the
# cardinality of the model
class_attribute :field_metadata_service
# This default service just give us the cardiality defined in the model.
Expand Down
2 changes: 1 addition & 1 deletion hydra-editor.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |s|
s.add_dependency "rails", ">= 4.2.0", "< 6"
s.add_dependency "active-fedora", ">= 9.0.0"
s.add_dependency "cancancan", "~> 1.8"
s.add_dependency "simple_form", '~> 3.2', '<= 3.5.0'
s.add_dependency "simple_form", '~> 3.2'
s.add_dependency 'sprockets-es6'
s.add_dependency "almond-rails", '~> 0.1'

Expand Down

0 comments on commit f523e17

Please sign in to comment.