2013-08-22 22 views
12

Cập nhật: Đây là do một tên sai chính tả tập tinActionController :: RoutingError: uninitialized liên tục MicropostsController

đúng:
~/sample_app/app/controllers/microposts_controller.rb

không đúng:
~/sample_app/app/controllers/microposts_contoller.rb


Đây là đóng góp đầu tiên của tôi ở đây, phản hồi về việc cải thiện điều này hoặc futu tái đăng được đánh giá cao :)

Ruby on Rails Hướng dẫn: Learn Web Development with Rails 4

Trong khi làm việc thông qua chương 10.3, tôi đã bị mắc kẹt. Cuối cùng, một tên tệp sai chính tả đã khiến tôi đuổi theo ma trong vài ngày.

$ rspec spec/requests/authentication_pages_spec.rb 
No DRb server is running. Running in local process instead ... 
...FF................ 

Failures: 

1) Authentication authorization for non-signed-in users in the Microposts controller submitting to the create action 
Failure/Error: before { post microposts_path } 
ActionController::RoutingError: 
uninitialized constant MicropostsController 
# ./spec/requests/authentication_pages_spec.rb:93:in `block (6 levels) in ' 

2) Authentication authorization for non-signed-in users in the Microposts controller submitting to the destroy action 
Failure/Error: before { delete micropost_path(FactoryGirl.create(:micropost)) } 
ActionController::RoutingError: 
uninitialized constant MicropostsController 
# ./spec/requests/authentication_pages_spec.rb:98:in `block (6 levels) in ' 

Finished in 0.92253 seconds 
21 examples, 2 failures 

Failed examples: 

rspec ./spec/requests/authentication_pages_spec.rb:94 # Authentication authorization for non-signed-in users in the Microposts controller submitting to the create action 
rspec ./spec/requests/authentication_pages_spec.rb:99 # Authentication authorization for non-signed-in users in the Microposts controller submitting to the destroy action 
+0

: đây là do một tên tập tin sai chính tả ~/sample_app /app/controllers/microposts_controller.rb (là microposts_contoller.rb) – 8legged

+3

Không bình luận, trả lời câu hỏi của riêng bạn. – fotanus

+1

Đồng ý bạn nên trả lời câu hỏi của bạn để người dùng không phải đọc toàn bộ bài đăng và nhận xét của bạn trước khi nhận ra rằng điều này đã được giải quyết. –

Trả lời

18

này là do một tên tập tin sai chính tả ~/sample_app/app/controllers/microposts_controller.rb (đã microposts_contoller.rb)

+0

Tôi đánh giá cao việc bạn đưa giải pháp lên hàng đầu. Tôi đã có cùng một vấn đề chính xác và có thể sửa chữa nó một cách nhanh chóng. :) –

+1

Tôi đã chuyển thư mục 'controllers' của mình lên một thư mục. – IIllIIll

1

này cũng có thể xảy ra nếu bạn có một con đường lồng ánh xạ một thư mục lồng nhau :

Started POST "/brokers/properties/5/images/upload" for ...

ActionController::RoutingError (uninitialized constant Brokers::ImagesController):

namespace :brokers do 
    resources :properties, only: [] do 
    collection do 
     post 'upload' 
    end 
    member do 
     resources :images, only: [] do 
     collection do 
      post 'upload' 
     end 
     end 
    end 
    end 
end 

Bạn Phải đặt tập tin images_controller.rb của bạn với cấu trúc sau:

-controllers 
|-brokers 
    |-images_controller.rb 

Lưu ý trong cấu trúc thư mục images_controller.rb là hậu duệ trực tiếp của các nhà môi giới.

Vì vậy, để cho Rails tìm lớp học của bạn không tạo ra một thư mục con bên trong propertiesbrokers lập bản đồ cấu trúc tuyến đường, nó phải được hậu duệ trực tiếp của các nhà môi giới

0

Trong routes.rb Tôi gõ resource thay vì resources

0

trong các tuyến đường của tôi: tôi đã có "/" thay vì "#" cho tất cả "nhận", do đó hãy thay đổi thành "#" nhận 'tất cả' => 'mặt tiền cửa hàng # all_items'

get 'categorical' = > 'mặt tiền cửa hàng # mặt hàng_by_category'

get 'thương hiệu' => 'cửa hàng # items_by_brand'

rằng cố định tất cả các lỗi của tôi.

0

tôi đã sai bao gồm bên dưới trong application_controller.rb

Đúng tôi:include ActionController::MimeResponds

Sai: Cập nhậtinclude ActionController::MimeResponse

# /controllers/api/v1/application_controller.rb 

module Api 
    module V1 
    class ApplicationController < ActionController::API 
     include ActionController::MimeResponds 
    end 
    end 
end 
Các vấn đề liên quan