thoughtbot / thoughtbot/administrate
Errors for STI models (undefined method for paths)
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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