norman / friendly_id

FriendlyId is the “Swiss Army bulldozer” of slugging and permalink plugins for ActiveRecord. It allows you to create pretty URL’s and work with human-friendly strings as if they were numeric ids for ActiveRecord models.
http://norman.github.io/friendly_id/
MIT License
6.13k stars 589 forks source link

uncommenting config.slug_limit causes crash #982

Closed ConfusedVorlon closed 2 years ago

ConfusedVorlon commented 2 years ago

uncommenting in the initialiser:

config.slug_limit = 255

immediately throws the error:

undefined method `slug_limit=' for #<#<Class:0x00007fd3d4c61e98>:0x00007fd3d4c61d58 @base=nil, @model_class=App(id: integer, name: string, identifier: string, created_at: datetime, updated_at: datetime, slug: string, account_id: integer), @defaults={}, @modules=[], @finder_methods=FriendlyId::FinderMethods, @routes=:friendly, @reserved_words=["new", "edit", "index", "session", "login", "logout", "users", "admin", "stylesheets", "assets", "javascripts", "images"]>

I'm on Rails 6.1.4

trace:

config/initializers/friendly_id.rb:63:in `block in <main>'
friendly_id (5.4.2) lib/friendly_id.rb:85:in `block in extended'
friendly_id (5.4.2) lib/friendly_id.rb:82:in `class_eval'
friendly_id (5.4.2) lib/friendly_id.rb:82:in `extended'
app/models/app.rb:20:in `extend'
app/models/app.rb:20:in `<class:App>'
app/models/app.rb:19:in `<main>'
bootsnap (1.9.1) lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
bootsnap (1.9.1) lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'

there is a github issue on a similar note which suggests just limiting on a per app basis (which does work) https://stackoverflow.com/questions/66036641/undefined-method-slug-limit-for-friendly-id

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

ConfusedVorlon commented 2 years ago

still true in

friendly_id (5.4.2) rails 7.0.2

notably - the rails app runs, but any test run through rspec breaks

An error occurred while loading ./spec/models/meditation_hls_spec.rb.
Failure/Error: extend FriendlyId

NoMethodError:
  undefined method `slug_limit=' for #<#<Class:0x000000016e1f7790>:0x000000016e1f7718 @base=nil, @model_class=Meditation(id: integer, slug: string, title: string, description: text, duration: integer, published: boolean, account_id: integer, created_at: datetime, updated_at: datetime, time_of_day: integer, brain_state: integer, guide_id: integer, artist_id: integer, hls_transcode_id: integer), @defaults={}, @modules=[], @finder_methods=FriendlyId::FinderMethods, @routes=:friendly, @reserved_words=["new", "edit", "index", "session", "login", "logout", "users", "admin", "stylesheets", "assets", "javascripts", "images"]>

    config.slug_limit = 25
          ^^^^^^^^^^^^^
# ./config/initializers/friendly_id.rb:63:in `block in <main>'
# /Users/rob/.rvm/gems/ruby-3.1.2/gems/friendly_id-5.4.2/lib/friendly_id.rb:85:in `block in extended'
# /Users/rob/.rvm/gems/ruby-3.1.2/gems/friendly_id-5.4.2/lib/friendly_id.rb:82:in `class_eval'
# /Users/rob/.rvm/gems/ruby-3.1.2/gems/friendly_id-5.4.2/lib/friendly_id.rb:82:in `extended'
# ./app/models/meditation.rb:48:in `extend'
# ./app/models/meditation.rb:48:in `<class:Meditation>'
# ./app/models/meditation.rb:36:in `<main>'
# /Users/rob/.rvm/gems/ruby-3.1.2/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
# /Users/rob/.rvm/gems/ruby-3.1.2/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
# /Users/rob/.rvm/gems/ruby-3.1.2/gems/zeitwerk-2.5.4/lib/zeitwerk/kernel.rb:27:in `require'
# ./spec/models/meditation_hls_spec.rb:38:in `<main>'
# /Users/rob/.rvm/gems/ruby-3.1.2/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:48:in `load'
# /Users/rob/.rvm/gems/ruby-3.1.2/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:48:in `load'