-1

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?

Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
mrudult
  • 2,480
  • 3
  • 35
  • 54
  • but why do I need that? i had created the controller with the **rails g controller order** method – mrudult Aug 11 '13 at 16:31
  • then the new action won't render. it gives **undefined method `orders_path'** at the simple_form_for thing. – mrudult Aug 11 '13 at 16:35
  • 2
    I think its better to stick to the rails convention and instead of fixing here and there generate a new controller using `rails g controller orders`, so that you don't have to change your code in many different places. – vee Aug 11 '13 at 16:36

1 Answers1

11

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.

Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214