how to fix the following error : undefined method `PUT' for #<ActionDispatch::Routing:: Mapper:0x3f8ee48> in rails 3.2?

vkbg

I am currently trying to create a shopping cart for my rails application and once populated my cart should be saved in the session.

Everytime i try to run the server to test if working or not, it seems my routes are not working at all...

See below my routes.rb, my cart controller and my index.

Any help will be appreciated.

routes.rb

    Sewingsupplies::Application.routes.draw do
  get "cart/index"

  get "cart/success"

  PUT "/cart/:id" => "cart#add"
  DELETE "/cart/:id" => "cart#remove"
  DELETE "/cart" => "cart#clear"
  POST "/cart/checkout"

  devise_for :admins

  resources :catalogues


  devise_for :users

cart controller

      def index
        sessions[:cart] = {}
        render 'cart/index'
      end

      def success
      end


      def add

        @catalogue = Catalogue.find(params[:id])
        cart = sessions[:cart]
        cart = {:catalogue => @catalogue.name,category => @catalogue.category, :code => @catalogue.code , :colour=> @catalogue.colour, :description => @catalogue.description, :image  => @catalogue.image , :unitprice => += @catalogue.unitprice, :unitquantity => +=1, :unitweight => += @catalogue.unitweight }
        sessions[:cart] = cart
        render 'cart/add'
      end
end

and my index page

<h1>Listing catalogues</h1>

<table>
  <tr>
    <th>Name</th>
    <th>Code</th>
    <th>Category</th>
    <th>Description</th>
    <th>Unitprice</th>
    <th>Unitquantity</th>
    <th>Unitweight</th>
    <th>Colour</th>
    <th>Image</th>
    <th>User</th>
    <th></th>
    <th></th>
    <th></th>
    <th></th>
  </tr>

<% @catalogues.each do |catalogue| %>
  <tr>
    <td><%= catalogue.name %></td>
    <td><%= catalogue.code %></td>
    <td><%= catalogue.category %></td>
    <td><%= catalogue.description %></td>
    <td><%= catalogue.unitprice %></td>
    <td><%= catalogue.unitquantity %></td>
    <td><%= catalogue.unitweight %></td>
    <td><%= catalogue.colour %></td>
    <td><%= image_tag(catalogue.image, :width => 150) if catalogue.image.present?%></td>
    <td><%= catalogue.user.email %></td>
    <td><%= link_to 'Show', catalogue %></td>
    <td><%= link_to 'Edit', edit_catalogue_path(catalogue) %></td>
    <td><%= link_to 'Destroy', catalogue, method: :delete, data: { confirm: 'Are you sure?' } %></td>
    <td><%= link_to "Add to cart", controller: "cart", action: "add", id: @catalogue.id, method: :post %></td>
  </tr>
<% end %>
</table>

<br />
<%= link_to "View cart", controller: "cart", action: "index" %>

<%= link_to 'New Catalogue', new_catalogue_path %>
Kirti Thorat

In your routes.rb file you have defined the routes with PUT and DELETE in uppercase. Define the routes in lowercase like put and delete as these are methods of ActionDispatch::Routing::Mapper class which are called to setup routes for your application. As ruby is case sensitive you need to call the method with correct case.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

undefined local variable or method `on' for #<ActionDispatch::Routing::Mapper:0x007fd3b4516a00>

undefined method `propfind' for ActionDispatch::Routing::Mapper

Undefined local variable or method `ho' for #<ActionDispatch::Routing::Mapper:0x00000103f4d0e0> (NameError)

Rails Routing Error (undefined local variable or method `micropost_comment')

How to fix "undefined method" error in destroy function

How to fix "undefined method `empty?' for #<ContactInformation:0x007fc8be45cc98>: error?

Rails 7 Error: undefined method `javascript_pack_tag' for #<ActionView::Base:0x0000000000c3c8>

How to fix 'undefined method error' when method exists?

How to fix sqlite3 error using rails and ruby

How to fix undefined method in nested models? post/create in Rails app

Very strange routing error in rails 3

Undefined method error in rails?

rails 3 link_to put method not working

How to fix the following bundler error?

How to fix this error in Angular routing?

Rails routing error with custom put action

How to fix 'Uncaught Error: Call to undefined method' in PHP

how fix this error "Undefined variable: products (0)"

No Method Error // Helper // Rails 3

How to fix "undefined reference to to `SSLv3_client_method`" during cURL custom installation

Call to undefined method; how to fix?

Integer to String, How can I fix the following error: "TypeError: Can't convert undefined to object"?

How do I fix the following error: "Cannot read property 'init' of undefined"?

Routing Error Undefined method for Controller:Class

How to fix this error in ionic 3

How fix the function to avoid error logs (Undefined offset: 2 in ....) - explode

How to fix the following "Error in hclust(d, method = hclustfun) : NA/NaN/Inf in foreign function call (arg 11)"

How to fix missing Template in Rails 3?

How to fix following ansible galaxy SSL error?