Domanda

I am trying to add a checkout link in order to direct a client to checkout view. I have a ProductsController, and an OrdersController where I defined the action for checkout. I am doing this because I set it so a product can have many orders.


class OrdersController < ApplicationController

  def checkout
    @product =  Product.find(params[:id])
  end

In my show.html.erb I added the line:

<%= link_to 'Contribute Now', order_checkout_path, :id => @product, :controller => "orders", :method => :get %> 

And my routes look like:

root :to => 'products#index'
match '/products'               => 'products#index'
get 'order/checkout'

resources :products
resources :orders

After running rake routes I get:

           root        /                                   products#index
       products        /products(.:format)                 products#index
 order_checkout GET    /order/checkout(.:format)           order#checkout
                GET    /products(.:format)                 products#index
                POST   /products(.:format)                 products#create
    new_product GET    /products/new(.:format)             products#new
   edit_product GET    /products/:id/edit(.:format)        products#edit
        product GET    /products/:id(.:format)             products#show
                PUT    /products/:id(.:format)             products#update
                DELETE /products/:id(.:format)             products#destroy

I have also defined a checkout.html.erb template.

After doing all that, I keep on getting an error of:

Routing Error
uninitialized constant OrderController
Try running rake routes for more information on available routes.

What am I missing?

È stato utile?

Soluzione

You want get 'orders/checkout', corresponding to the plural form of "order" used in your controller name.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top