Skip to content

Commit

Permalink
Fix NoMethodError on Rails 7.x (#114)
Browse files Browse the repository at this point in the history
When attempting to run `rails g rails_settings:migration` in a Rails `7.x` project, the generator fails with a `NoMethodError` out of `activerecord-7.1.0/lib/active_record/dynamic_matchers.rb:22`

The `timestamped_migrations` method was moved from `ActiveRecord::Base` to `ActiveRecord` in the `7.x` branch, see
rails/rails@bcd6c0f
  • Loading branch information
nicbet authored Oct 20, 2023
1 parent bcc62e9 commit e47ab50
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ def create_migration_file
end

def self.next_migration_number(dirname)
if ActiveRecord::Base.timestamped_migrations
if timestamped_migrations?
Time.now.utc.strftime('%Y%m%d%H%M%S')
else
'%.3d' % (current_migration_number(dirname) + 1)
end
end

def self.timestamped_migrations?
(ActiveRecord::Base.respond_to?(:timestamped_migrations) && ActiveRecord::Base.timestamped_migrations) ||
(ActiveRecord.respond_to?(:timestamped_migrations) && ActiveRecord.timestamped_migrations)
end
end
end

0 comments on commit e47ab50

Please sign in to comment.