Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sitepress does not work on Rails 7.1: "uninitialized constant PageHelper" #50

Closed
collimarco opened this issue Nov 9, 2023 · 8 comments

Comments

@collimarco
Copy link

I am upgrading a Rails application that uses Sitepress from Rails 7 to Rails 7.1.1.

After the upgrade I get this error that prevents all tests from running:

$ bundle exec rspec

An error occurred while loading ./spec/api/application_spec.rb.
Failure/Error: require 'rspec/rails'

NameError:
  uninitialized constant PageHelper
# ./spec/rails_helper.rb:7:in `<top (required)>'
# ./spec/api/application_spec.rb:1:in `require'
# ./spec/api/application_spec.rb:1:in `<top (required)>'

The error is definitely related to this gem because I don't have any other PageHelper (I have only the default one included by Sitepress). I also made some research and I found this old related issue: rails/rails#43205 (I also tried to run the tests again, as suggested in that issue, but the problem persists).

Do you have any idea on how to solve this?

@collimarco
Copy link
Author

The loading issue is also present in the other environments (not just in the test env). For example:

undefined method `link_to_page' for #<ActionView::Base:0x000000000181c8>

link_to_page is a method defined in Sitepress PageHelper, so it means that that file is not loaded/required properly in the new Rails versions.

@collimarco
Copy link
Author

Here's a temporary workaround for this issue:

# config/application.rb
config.autoload_paths << config.root.join('app/content/helpers')

This code (or something similar) should probably go inside this gem directly.

@collimarco
Copy link
Author

It's even worse... While the workaround works on my local machine, the tests running on GitHub CI fail with a new error:

An error occurred while loading ./spec/api/application_spec.rb.
Failure/Error: require File.expand_path('../../config/environment', __FILE__)

Zeitwerk::NameError:
  expected file /home/runner/work/myapp/myapp/app/content/models/page_model.rb to define constant Models::PageModel, but didn't

@collimarco
Copy link
Author

This seems to fix both errors:

# config/application.rb

config.autoload_paths << config.root.join('app/content/helpers')
config.autoload_paths << config.root.join('app/content/models')

This code (or something equivalent) should be added to this gem, in order to solve this issue.

@bradgessler
Copy link
Contributor

It's an issue with autoloading changes introduced in Rails 7.1. Checkout the issue at #47 for more info.

@moviendome
Copy link

Just upgraded to 7.1.2 and now it's working.

@bradgessler
Copy link
Contributor

Great! Closing issue.

@collimarco
Copy link
Author

Just upgraded to 7.1.2 and now it's working.

Yes, great, I confirm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants