我是 Rails 平台的新手。我正在使用Apartment gem构建一个多租户应用程序。我正在关注https://medium.com/@balogic/using-apartment-gem-to-implement-multitenant-concept-in-rails-b86f7d9e37c5这个指南来学习如何使用这个 gem。但是当我搭建脚手架或生成用户模型时,我收到以下错误:
$ rails g scaffold Users email name subdomain
C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.1.0/lib/action _dispatch/middleware/stack.rb:35:in `build': undefined method `new' for "Apartme nt::Elevators::Subdomain":String (NoMethodError)
Did you mean? next
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.1 .0/lib/action_dispatch/middleware/stack.rb:99:in `block in build'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.1 .0/lib/action_dispatch/middleware/stack.rb:99:in `each'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.1 .0/lib/action_dispatch/middleware/stack.rb:99:in `inject'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.1 .0/lib/action_dispatch/middleware/stack.rb:99:in `build'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.1.0 /lib/rails/engine.rb:508:in `block in app'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.1.0 /lib/rails/engine.rb:504:in `synchronize'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.1.0 /lib/rails/engine.rb:504:in `app'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.1.0 /lib/rails/application/finisher.rb:45:in `block in <module:Finisher>'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.1.0 /lib/rails/initializable.rb:30:in `instance_exec'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.1.0 /lib/rails/initializable.rb:30:in `run'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.1.0 /lib/rails/initializable.rb:59:in `block in run_initializers'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/2.3.0/tsort.rb:228:in `block i n tsort_each'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/2.3.0/tsort.rb:350:in `block ( 2 levels) in each_strongly_connected_component'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/2.3.0/tsort.rb:431:in `each_st rongly_connected_component_from'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/2.3.0/tsort.rb:349:in `block i n each_strongly_connected_component'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/2.3.0/tsort.rb:347:in `each'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/2.3.0/tsort.rb:347:in `call'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/2.3.0/tsort.rb:347:in `each_st rongly_connected_component'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/2.3.0/tsort.rb:226:in `tsort_e ach'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/2.3.0/tsort.rb:205:in `tsort_e ach'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.1.0 /lib/rails/initializable.rb:58:in `run_initializers'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.1.0 /lib/rails/application.rb:353:in `initialize!'
from C:/Sites/multitenant_app/config/environment.rb:5:in `<top (required )>'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.1.0 /lib/rails/application.rb:329:in `require'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.1.0 /lib/rails/application.rb:329:in `require_environment!'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.1.0 /lib/rails/command/actions.rb:16:in `require_application_and_environment!'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.1.0 /lib/rails/commands/generate/generate_command.rb:19:in `perform'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/thor-0.19.4/li b/thor/command.rb:27:in `run'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/thor-0.19.4/li b/thor/invocation.rb:126:in `invoke_command'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/thor-0.19.4/li b/thor.rb:369:in `dispatch'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.1.0 /lib/rails/command/base.rb:63:in `perform'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.1.0 /lib/rails/command.rb:44:in `invoke'
from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.1.0 /lib/rails/commands.rb:16:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
**注意:** 我的 Rails 版本是 5.0.1,Ruby 版本是 2.3.0