Error when visiting consultations
Closed this issue · 1 comments
aitorlb commented
Describe the bug
Consultations frontend crashes when using decidim-consultations
with decidim-term_customizer
.
To Reproduce
Steps to reproduce the behavior:
- Generate a development_app
$ bundle exec rake development_app
- Add the consultations gem to the development_app Gemfile
gem "decidim-consultations", Decidim::TermCustomizer::DECIDIM_VERSION
- Install the gem and run migrations
$ bundle
$ bundle exec rails decidim_consultations:install:migrations
$ bundle exec rails db:migrate
- Visit http://localhost:3000/consultations
- See error
Expected behavior
Should not crash.
Screenshots
If applicable, add screenshots to help explain your problem.
Stacktrace
If applicable, add the error stacktrace to help explain your problem.
/home/aitorlopez/workspace/decidim-codit/decidim/decidim-core/app/controllers/concerns/decidim/participatory_space_context.rb:42:in `current_participatory_space'
/home/aitorlopez/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/bundler/gems/decidim-module-term_customizer-a0055f708cfe/lib/decidim/term_customizer/context/controller_context.rb:19:in `resolve!'
/home/aitorlopez/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/bundler/gems/decidim-module-term_customizer-a0055f708cfe/lib/decidim/term_customizer/context/base.rb:24:in `initialize'
/home/aitorlopez/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/bundler/gems/decidim-module-term_customizer-a0055f708cfe/lib/decidim/term_customizer/engine.rb:20:in `new'
/home/aitorlopez/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/bundler/gems/decidim-module-term_customizer-a0055f708cfe/lib/decidim/term_customizer/engine.rb:20:in `block (2 levels) in <class:Engine>'
ahukkanen commented
This is "fixed" by 5d7dca1 (the not crashing part).
Hard to fix "properly" without that core patch but there is a workaround for this issue:
- Create a custom controller context for Term Customizer
# frozen_string_literal: true
# lib/term_customizer_custom_controller_context.rb
class TermCustomizerCustomControllerContext < Decidim::TermCustomizer::Context::ControllerContext
def resolve!
env = data[:headers].env
controller = env["action_controller.instance"]
@organization = env["decidim.current_organization"]
if controller.respond_to?(:current_consultation)
consultation = controller.send(:current_consultation)
@space = consultation
@component = env["decidim.current_component"]
return
end
super
end
end
- Apply that to Term Customizer
# config/initializers/term_customizer.rb
require "term_customizer_custom_controller_context"
Decidim::TermCustomizer.controller_context_class = TermCustomizerCustomControllerContext