uninitialized constant OrdersController

9k views Asked by At

I have a Order controller and a *Order model*like this ;-

class OrderController < ApplicationController

def new
    @cart=current_cart
    if @cart.items.empty?
        flash[:error]="Your cart is empty"
        redirect_to :back
        return
    end

    @order=Order.new

end

def create
    @order=Order.new
end

end  

My routes.rb has

get "order/new"
resources :orders  

And a form in new.html.erb

<%= simple_form_for(@order, html: {class: 'form-horizontal control-group '}) do |f| %>   
<%= f.button :submit, "Place Order", class: "btn btn-large btn-primary" %>
<% end %>  

I do also have other fields in the form.

But when I submit the form it throws the error

uninitialized constant OrdersController

What's wrong?

1

There are 1 answers

0
Andrew Marshall On BEST ANSWER

Your controller name is OrderController (singular) and the error is complaining it cannot find OrdersController (plural). You also specified resources :orders in your routes (plural) which must match the controller name.

Rename your controller to OrdersController; this follows the Rails convention of plural controller names.