2010-12-31 26 views
28

Tôi là một Ruby nuby (và mới đối với Stack Overflow) làm việc trên Rails Tutorial by Michael Hartl và đột nhiên máy chủ phát triển của tôi won't load and keeps exiting. Bảng điều khiển cũng sẽ không tải và thông số Rspec/tạo lỗi/ngoại lệ. Tôi bao gồm một số đầu ra từ các thiết bị đầu cuối, giúp đỡ của bạn được nhiều đánh giá cao.Tại sao máy chủ phát triển của tôi không tải? default_controller_and_action ': missing: action (ArgumentError)

Exiting 
/Users/ameedachowdhury/.rvm/gems/[email protected]/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:164:in `default_controller_and_action': missing :action (ArgumentError) 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:68:in `normalize_options!' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:51:in `initialize' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:261:in `new' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:261:in `match' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:1112:in `match' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:1297:in `match' 
    from /Users/ameedachowdhury/rails_projects/railstutorial/config/routes.rb:11:in `block in <top (required)>' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/actionpack-3.0.3/lib/action_dispatch/routing/route_set.rb:233:in `instance_exec' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/actionpack-3.0.3/lib/action_dispatch/routing/route_set.rb:233:in `draw' 
    from /Users/ameedachowdhury/rails_projects/railstutorial/config/routes.rb:1:in `<top (required)>' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `load' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `block in load' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `block in load_dependency' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:596:in `new_constants_in' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `load' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/railties-3.0.3/lib/rails/application.rb:127:in `block in reload_routes!' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/railties-3.0.3/lib/rails/application.rb:127:in `each' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/railties-3.0.3/lib/rails/application.rb:127:in `reload_routes!' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/railties-3.0.3/lib/rails/application.rb:120:in `block in routes_reloader' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/activesupport-3.0.3/lib/active_support/file_update_checker.rb:32:in `call' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/activesupport-3.0.3/lib/active_support/file_update_checker.rb:32:in `execute_if_updated' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/railties-3.0.3/lib/rails/application/finisher.rb:51:in `block (2 levels) in <module:Finisher>' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/railties-3.0.3/lib/rails/application/finisher.rb:52:in `call' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/railties-3.0.3/lib/rails/application/finisher.rb:52:in `block in <module:Finisher>' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `instance_exec' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `run' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/railties-3.0.3/lib/rails/initializable.rb:50:in `block in run_initializers' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `each' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `run_initializers' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/railties-3.0.3/lib/rails/application.rb:134:in `initialize!' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/railties-3.0.3/lib/rails/application.rb:77:in `method_missing' 
    from /Users/ameedachowdhury/rails_projects/railstutorial/config/environment.rb:5:in `<top (required)>' 
    from /Users/ameedachowdhury/rails_projects/railstutorial/config.ru:3:in `require' 
    from /Users/ameedachowdhury/rails_projects/railstutorial/config.ru:3:in `block in <main>' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/rack-1.2.1/lib/rack/builder.rb:46:in `instance_eval' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/rack-1.2.1/lib/rack/builder.rb:46:in `initialize' 
    from /Users/ameedachowdhury/rails_projects/railstutorial/config.ru:1:in `new' 
    from /Users/ameedachowdhury/rails_projects/railstutorial/config.ru:1:in `<main>' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/rack-1.2.1/lib/rack/builder.rb:35:in `eval' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/rack-1.2.1/lib/rack/builder.rb:35:in `parse_file' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/rack-1.2.1/lib/rack/server.rb:162:in `app' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/rack-1.2.1/lib/rack/server.rb:248:in `wrapped_app' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/rack-1.2.1/lib/rack/server.rb:213:in `start' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/railties-3.0.3/lib/rails/commands/server.rb:65:in `start' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/railties-3.0.3/lib/rails/commands.rb:30:in `block in <top (required)>' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/railties-3.0.3/lib/rails/commands.rb:27:in `tap' 
    from /Users/ameedachowdhury/.rvm/gems/[email protected]/gems/railties-3.0.3/lib/rails/commands.rb:27:in `<top (required)>' 
    from script/rails:6:in `require' 
    from script/rails:6:in `<main>' 
ameeda-chowdhurys-macbook:railstutorial ameedachowdhury$ 

Trả lời

69

Khi tôi chạy vào vấn đề này, đó là bởi vì một trong những tuyến đường trong routes.rb có một dấu gạch chéo (/) thay vì băm (#) khi sử dụng cú pháp controller#action (tôi đã sử dụng "điều khiển/hành động ", không chính xác). Ví dụ, tôi vô tình có root :to => 'home/index'. Nó được cho là root :to => 'home#index'.

Tôi đã tìm thấy giải pháp này trong here.

+3

Dấu gạch chéo 'thay vì bài toán băm – Catfish

0

Trong trường hợp của tôi, nguyên nhân là do hậu tố bị gạch chéo '/' trong một số tuyến đường của tôi. Ví dụ.

post 'load_query/' 

Sau khi loại bỏ hậu tố này để

post 'load_query' 

nó làm việc.

8

Điều này là do các tuyến đường không chính xác -
Vui lòng kiểm tra cấu hình/tuyến đường của bạn.rb, ngay cả khi một tuyến đường được đề cập là sai thì lỗi này được ném !!
Ngoài ra hãy chắc chắn rằng con đường là

'/url/for/something' => 'controller#action' 

hoặc

root :to => 'controller#action 
+0

đây là giải pháp, cảm ơn. bạn có thể có cùng lỗi như tôi đã có, tôi sẽ thực hiện cùng một hướng dẫn. chỉ cần nhận xét ra nguyên liệu sửa đổi cuối cùng trong routes.rb và bạn sẽ thấy tuyến đường nào gây ra lỗi, sau đó sửa cú pháp. – YogiZoli

2

Tôi cũng một Ruby nuby và đã có những lỗi tương tự khi làm việc trên Rails Tutorial bởi Michael Hartl. Nếu bạn giống tôi, bạn có thể chỉ cần nhập vào tất cả các mã xuất hiện trong cuốn sách thực sự đọc hoặc hiểu văn bản. Không phải mọi thứ đều từng bước. Trong trường hợp chứng minh camel so với trường hợp con rắn Hartl cho thấy một hộp với đoạn mã sau

$ rails generate controller static_pages ... 

Ở đây, Hartl chỉ đơn giản là cố gắng để tương phản hướng dẫn để tạo ra một bộ điều khiển StaticPages sử dụng trường hợp con rắn, chứ không phải là trường hợp lạc đà, được thực hiện trong Liệt kê 3.4. Các dấu chấm "..." chỉ đơn giản là để chỉnh sửa hoặc cắt bớt phần còn lại của các hướng dẫn cho dòng cmd. Tôi gõ vào chính xác những gì được hiển thị và vết thương lên những điều sau đây tuyến đường của tôi file:

SampleApp::Application.routes.draw do 
get "static_pages/..." 

get "static_pages/home" 

get "static_pages/help" 

mở tập tin tuyến đường của bạn, xóa

get "static_pages/..." 

lưu các tập tin tuyến đường, và thử khởi ray máy chủ một lần nữa .

Tôi cũng đã phá hủy "đường ray tạo bộ điều khiển static_pages ..." Không chắc chắn nếu điều đó có hiệu lực, nhưng bây giờ mọi thứ hoạt động.

1

Theo mặc định bạn có được điều này:

Rails.application.routes.draw do 
    get 'static_pages/...' 

    get 'static_pages/home' 

    get 'static_pages/help' 

chỉ cần xóa NÀY:

get 'static_pages/...' 

VÀ BẠN SẼ CÓ NÀY TRONG FILE routes.rb

Rails.application.routes.draw do 

    get 'static_pages/home' 

    get 'static_pages/help' 
0

thay đổi thư mục gốc mặc định của bạn trong tệp routes.rb.

get "static_pages#home" TO root to: 'static_pages#home' 

Tôi đã trải qua cùng một vấn đề và thay đổi trên đã hiệu quả đối với tôi.

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