Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A administrate
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 96
    • Issues 96
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 32
    • Merge requests 32
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • thoughtbot, inc.
  • administrate
  • Merge requests
  • !967

Change const_get to constantize to fix undefined method `default_scoped'

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/joshua5201/master into master Sep 01, 2017
  • Overview 5
  • Commits 1
  • Pipelines 0
  • Changes 1

Created by: joshua5201

Found a strange problem when my namespace and model name are the same (e.g. Order::Order) config/routes

resources :order do
  resources :orders
end

When restart / modify source and the rails got reloaded, accessing /admin/order/orders and I get:

undefined method `default_scoped' for Order:Module

No problem if I get back to /admin and click the navigator link in the left.

And I found that in rails console

Object.const_get('Order::Order') 
=> Order
"Order::Order".constantize 
=> Order::Order

using constantize, I can get the correct model class name.

p.s. my model sources

app/models/order.rb

module Order
  def self.table_name_prefix
    'order_'
  end
end

app/models/order/order.rb

class Order::Order < ApplicationRecord
end
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/joshua5201/master