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

Fix NoMethodError for ActiveRecord 7.1.2 in when running rails generate shortener #165

Closed
wants to merge 2 commits into from

Conversation

jonathandean
Copy link
Contributor

Running rails generate shortener on ActiveRecord 7.1.2 produces a NoMethodError:

~/.rvm/gems/ruby-3.2.2@maitre-d/gems/activerecord-7.1.2/lib/active_record/dynamic_matchers.rb:22:in `method_missing': undefined method `timestamped_migrations' for ActiveRecord::Base:Class (NoMethodError)
	from ~/.rvm/gems/ruby-3.2.2@maitre-d/gems/shortener-1.0.1/lib/generators/shortener/shortener_generator.rb:12:in `next_migration_number'
	from ~/.rvm/gems/ruby-3.2.2@maitre-d/gems/railties-7.1.2/lib/rails/generators/migration.rb:43:in `set_migration_assigns!'
	from ~/.rvm/gems/ruby-3.2.2@maitre-d/gems/railties-7.1.2/lib/rails/generators/migration.rb:59:in `migration_template'
	from ~/.rvm/gems/ruby-3.2.2@maitre-d/gems/shortener-1.0.1/lib/generators/shortener/shortener_generator.rb:20:in `create_migration_file'

This was resolved by replacing ActiveRecord::Base.timestamped_migrations with ActiveRecord.timestamped_migrations

Fixes error: 

`method_missing': undefined method `timestamped_migrations' for ActiveRecord::Base:Class (NoMethodError)
	from ~/.rvm/gems/ruby-3.2.2@maitre-d/gems/shortener-1.0.1/lib/generators/shortener/shortener_generator.rb:12:in `next_migration_number'
…d-7_1_2

Fix NoMethodError for ActiveRecord 7.1.2 in ShortenerGenerator
@fschwahn
Copy link
Collaborator

Do you know in which rails versions this is supported? The generator is not covered by tests, so we cannot rely on that. Backwards compatible alternative would be:

if ActiveRecord.respond_to?(:timestamped_migrations) ? ActiveRecord.timestamped_migrations : ActiveRecord::Base.timestamped_migrations

Or you could try writing a spec for the generator (maybe this is supported all the way back to rails 4.2)

@fschwahn
Copy link
Collaborator

I cherry-picked your changes into #168 and merged them. Thank you for your contribution.

@fschwahn fschwahn closed this Feb 19, 2024
@dsheard
Copy link

dsheard commented Apr 7, 2024

Still getting this issue, has it been released in version 1.0.1?

@fschwahn
Copy link
Collaborator

fschwahn commented Apr 8, 2024

No, this has not been released yet. @jpmcgrath the generator of the current released version is incompatible with rails 7.1 - can you release a new version?

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

Successfully merging this pull request may close these issues.

3 participants