简体   繁体   中英

rails RESTful routing with Devise not working

Using Devise 3.0 and Rails 4.0

I can't seem to get my normal restful routes working.

When I visit URL/products/ or URL/products/3460 (to view the "show" action of a specific product) I'm given the following error respectively:

Missing Template

Missing template products/show, application/show with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}.

Products_controller.rb

class ProductsController < ApplicationController

def index
  @products = Product.all
end

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

respond_to do |format|
  format.html # show.html.erb
  format.json { render json: @product }
end

end 

I also have index.html.erb and show.html.erb views files in app/views/product

rake routes output:

      Prefix Verb   URI Pattern                  Controller#Action
    new_user_session GET    /users/sign_in(.:format)     devise/sessions#new
        user_session POST   /users/sign_in(.:format)     devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format)    devise/sessions#destroy
            products 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
                     PATCH  /products/:id(.:format)      products#update
                     PUT    /products/:id(.:format)      products#update
                     DELETE /products/:id(.:format)      products#destroy
                root GET    /                            application#index
                     GET    /products(.:format)          products#index
               login GET    /login(.:format)             devise/sessions#new
              logout DELETE /logout(.:format)            devise/sessions#destroy

Anyone see anything obvious I'm missing?

show.html.erb view file must be present in app/views/products directory.

Note products (plural) and not product (singular).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM