thoughtbot / thoughtbot/administrate

Errors for STI models (undefined method for paths)

Open
#703 24 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

models resolver
Dominant language
JavaScript
Stars
6k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

I have models:

  • Topic < ActiveRecord::Base
  • Topics::News < Topic
  • Topics::Article < Topic

The $ rails generate administrate:install created following routes:

# config/routes.rb
# ...
  namespace :admin
    resources :topics
    root to: 'topics#index'
  end

And /admin/ had given me following error:

undefined method `admin_topics_article_path' for #<#<Class:0x007fb0bbf85e30>:0x007fb0c7d159f0>
Did you mean?  admin_topics_path

I think it's problem with how Administrate or Rails handles single table inheritance and model_name of STI models.

My temporary workaround:

class Topic < ActiveRecord::Base
  def self.model_name
    return super if self == Topic
    Topic.model_name
  end
end

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with config/routes.rb and the /admin/ entry point, then reproduce the undefined admin_topics_article_path error using the Topic, Topics::News, and Topics::Article STI models. Done means the admin topics pages resolve their generated paths without the reported error while preserving the base Topic routing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.