2013-11-02 17 views
8

Vì vậy, tôi đã làm việc trên Rails và hơi thất vọng với mô hình người dùng của mình nên tôi đã phá hủy nó (tôi cũng đang sử dụng ý tưởng có thể là nguồn lỗi). Trong phòng thủ của tôi, tôi đã mệt mỏi, thất vọng, và một chút về phía lời khuyên. Tôi đã cố gắng thêm nó trở lại với một đơn giản rails g scaffold user first:text last:text, nhưng tôi nhận được lỗi sau khi cố gắng tạo mô hình. Làm cách nào để khắc phục sự cố này?Sau khi phá hủy mô hình người dùng, không thể thêm mô hình người dùng trở lại trong

/home/action/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/inflector/methods.rb:226:in `const_get': uninitialized constant User (NameError)     
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/inflector/methods.rb:226:in `block in constantize'             
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/inflector/methods.rb:224:in `each'                 
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/inflector/methods.rb:224:in `inject'                
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/inflector/methods.rb:224:in `constantize'               
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.1.1/lib/devise.rb:285:in `get'                 
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.1.1/lib/devise/mapping.rb:77:in `to'                 
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.1.1/lib/devise/mapping.rb:72:in `modules'                
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.1.1/lib/devise/mapping.rb:89:in `routes'                
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.1.1/lib/devise/mapping.rb:156:in `default_used_route'             
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.1.1/lib/devise/mapping.rb:66:in `initialize'               
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.1.1/lib/devise.rb:319:in `new'                 
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.1.1/lib/devise.rb:319:in `add_mapping'               
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.1.1/lib/devise/rails/routes.rb:210:in `block in devise_for'             
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.1.1/lib/devise/rails/routes.rb:209:in `each'                 
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.1.1/lib/devise/rails/routes.rb:209:in `devise_for'               
     from /home/action/workspace/surrigo/config/routes.rb:2:in `block in <top (required)>'           
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-4.0.0/lib/action_dispatch/routing/route_set.rb:316:in `instance_exec'              
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-4.0.0/lib/action_dispatch/routing/route_set.rb:316:in `eval_block'               
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-4.0.0/lib/action_dispatch/routing/route_set.rb:294:in `draw'                 
     from /home/action/workspace/surrigo/config/routes.rb:1:in `<top (required)>'              
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'             
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application/routes_reloader.rb:40:in `each'                 
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application/routes_reloader.rb:40:in `load_paths'               
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application/routes_reloader.rb:16:in `reload!'                
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application/routes_reloader.rb:26:in `block in updater'              
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/file_update_checker.rb:75:in `call'                 
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/file_update_checker.rb:75:in `execute'                
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application/routes_reloader.rb:27:in `updater'                
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application/routes_reloader.rb:6:in `execute_if_updated'             
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'           
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `instance_exec'              
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `run'                 
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/initializable.rb:55:in `block in run_initializers'           
     from /home/action/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'             
     from /home/action/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'    
     from /home/action/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'        
     from /home/action/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'       
     from /home/action/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:180:in `each'                 
     from /home/action/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'         
     from /home/action/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'               
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/initializable.rb:54:in `run_initializers'              
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application.rb:215:in `initialize!'               
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in `method_missing'              
     from /home/action/workspace/surrigo/config/environment.rb:13:in `<top (required)>'               
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application.rb:189:in `require_environment!'             
     from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands.rb:45:in `<top (required)>'              
     from bin/rails:4:in `require'                                                   
     from bin/rails:4:in `<main>' 
+0

Bạn đã di chuyển chưa? – hiattp

+0

Di chuyển bật cùng lỗi – Kevrone

+0

Rake bị hủy! hằng số không được khởi tạo Người dùng /home/action/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/inflector/methods.rb:226:in .... – Kevrone

Trả lời

30

Tháo dòng devise_for :users từ routes.rb và thử chạy rails g scaffold user first:text last:text. Nó sẽ hoạt động tốt.

Phương pháp devise_for yêu cầu mô hình User hiển thị. Do đó, nó không thành công khi tải môi trường đường ray khi bạn chạy lệnh giàn giáo đường ray

0

Có thể bạn có xung đột với quy ước đặt tên?

Hãy thử

rails g scaffold User first:text last:text 

để thay thế. Bạn đang tạo ra một mô hình cho lớp người dùng (Lớp học được vốn hóa CamelCase trong Ruby)

Các vấn đề liên quan