2016-11-28 12 views
1

Railsアプリケーションのルーティングに問題があります。未初期化定数CustomersController - Rails

uninitialized constant CustomersController 

これは私が従うことをしようとしているリンクです:私はnew_customer_pathへのリンクをたどるしようとすると、私はこのエラーを取得します。私のムービーコントローラの「新しい」ページにあります。

<div class="row"> 
<div class="col-xs-12"> 
    <hr /> 
    <%= link_to "Add Customer", new_customer_path, class: 'white' %> 
</div> 
</div> 

カスタマー・コントローラー:

class CustomerController < ApplicationController 
    def new 
    @customer = Customer.new 
    end 

    def create 
    @customer = Customer.new(customer_params) 
    if @customer.save 
     redirect_to new_customer_path 
    end 
    end 

    private 

    def customer_params 
    params.require(:customer).permit(:fname, :lname, :telephone, :email) 
    end 

end 

ルート:

Rails.application.routes.draw do 
    resources :customers 

    resources :movies do 
    resources :rentals 
    end 
    root 'movies#new' 
end 

カスタマーモデル:

class Customer < ApplicationRecord 
    has_many :rentals 
end 

任意の考えここで "新しい" ページの関連部分があります/ tipsは非常に高く評価されるでしょう!

答えて

4

sが不足している可能性がありますか?

  • モデルは単数形である:Object
  • コントローラが複数ある:ObjectsController

これがあれば変更することができる

class CustomerController < ApplicationControllerclass CustomersController < ApplicationController

レールを意味設定より規約がされなければなりませんあなたは好きですが、私はあなたがagを持っていなければ大会に固執しますおおよその理由。

+0

これは良いキャッチです!残念ながら、それはより広い問題を修正しませんでした。これで、代わりに「初期化されていない定数CustomersController」が表示される –

+5

コントローラーの名前を変更しましたが、そのコントローラーの名前は変更しませんでしたか? –

+1

それは問題でした。あなたがた両方に感謝します! –

関連する問題