2013-08-22 95 views
12

更新:這是由於拼寫錯誤的文件名的ActionController :: RoutingError:未初始化不斷MicropostsController

正確:
~/sample_app/app/controllers/microposts_controller.rb

不正確:
~/sample_app/app/controllers/microposts_contoller.rb


這是我在這裏做出的第一個貢獻,就是改善這個還是futu的反饋重新張貼理解:)

Ruby on Rails的教程:Learn Web Development with Rails 4

,同時通過章10.3工作,我被困。最後,拼寫錯誤的文件名讓我追了幾天鬼。

$ 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

更新:這是由於拼寫錯誤的文件名〜/ sample_app /app/controllers/microposts_controller.rb(was microposts_contoller.rb) – 8legged

+3

不要評論,回答你自己的問題。 – fotanus

+1

同意你應該回答你的問題,以便用戶在意識到這個問題已經解決之前不必閱讀你的整篇文章和評論。 –

回答

18

這是由於拼寫錯誤的文件名〜/ sample_app /應用/控制器/ microposts_controller.rb(是microposts_contoller.rb)

+0

我很欣賞你把解決方案放在最頂端。我有完全相同的問題,並能夠迅速解決它。 :) –

+1

我把我的'controllers'文件夾移到了一個目錄。 – IIllIIll

1

,如果你有一個嵌套的路由映射一個嵌套的目錄也會發生這種情況:

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 

你必須把你的images_controller.rb文件具有以下結構:在目錄結構中images_controller.rb

-controllers 
|-brokers 
    |-images_controller.rb 

通知是經紀人的直系後裔。

因此,爲了讓Rails的找到你的類不創建一個子目錄propertiesbrokers映射航線結構,它必須是經紀人

0

的直系後裔在routes.rb我輸入resource代替resources

0

在我的路線:我有「/」而不是「#」所有的「獲得」,所以更改爲「#」 get'all'=>'storefront#all_items'

get'categorical'= >'storefront#items_by_category'

得到 '品牌'=> '店面#items_by_brand'

是固定我的所有錯誤。

0

我曾錯誤地包含在我的application_controller.rb

更正如下:include ActionController::MimeResponds

錯誤:include ActionController::MimeResponse

# /controllers/api/v1/application_controller.rb 

module Api 
    module V1 
    class ApplicationController < ActionController::API 
     include ActionController::MimeResponds 
    end 
    end 
end 
相關問題