Skip to content

Commit

Permalink
WIP: Rails upgrade to 6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
benlovell committed Feb 19, 2024
1 parent c84c153 commit 57908e3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ gemspec

ruby IO.read('.ruby-version').chomp

gem 'rails', '5.0.7.2'
gem 'rails', '~> 6.0.0'

group :development, :test do
gem 'brakeman', require: false
Expand Down
18 changes: 17 additions & 1 deletion lib/dough/forms/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@ class Builder < ActionView::Helpers::FormBuilder
# <%= f.errors_summary %>
#
def errors_summary
render(errors_summary_partial_name, errors: object_errors) if object_errors.present?
view_renderer.render(view_context, partial: errors_summary_partial_name, locals: { errors: object_errors }) if object_errors.present?
end

def compiled_method_container
view_context.compiled_method_container
end

def in_rendering_context(options, &blk)
view_context.in_rendering_context(options, &blk)
end

def _run(*args, &blk)
view_context._run(*args, &blk)
end

# This is the partial used to render the summary errors.
Expand Down Expand Up @@ -108,6 +120,10 @@ def lookup_context
ActionView::LookupContext.new(ActionController::Base.view_paths + partial_paths)
end

def view_context
ActionView::Base.new
end

def view_renderer
ActionView::Renderer.new(lookup_context)
end
Expand Down
20 changes: 18 additions & 2 deletions lib/dough/forms/builders/validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,26 @@ module ValidationModule
include ActionView::Helpers::TranslationHelper

def validation_summary
render 'summary_for_errors', errors: errors, error_prefix: error_prefix
view_renderer.render(view_context, partial: 'summary_for_errors', locals: { errors: errors, error_prefix: error_prefix })
end

def compiled_method_container
view_context.compiled_method_container
end

def in_rendering_context(options, &blk)
view_context.in_rendering_context(options, &blk)
end

def _run(*args, &blk)
view_context._run(*args, &blk)
end

def errors_for(subject = nil, field)
subject ||= object
filtered_errors = errors.select { |hash| hash[:object] == subject && hash[:field] == field }

render partial: 'errors_for_field', collection: filtered_errors, as: 'error', locals: { error_prefix: error_prefix }
view_renderer.render(view_context, partial: 'errors_for_field', collection: filtered_errors, as: 'error', locals: { error_prefix: error_prefix })
end

def validates(*models)
Expand All @@ -38,6 +50,10 @@ def view_renderer
ActionView::Renderer.new(lookup_context)
end

def view_context
ActionView::Base.new(lookup_context)
end

private

def error_models
Expand Down

0 comments on commit 57908e3

Please sign in to comment.