【问题标题】:rails RESTful routing with Devise not working使用Devise的rails RESTful路由不起作用
【发布时间】:2014-04-07 21:12:19
【问题描述】:

使用 Devise 3.0 和 Rails 4.0

我似乎无法让我正常的宁静路线工作。

当我访问 URL/products/URL/products/3460(查看特定产品的“显示”操作)时,我收到以下错误分别:

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 

我在 app/views/product

中也有 index.html.erb 和 show.html.erb 视图文件

rake 路线输出:

      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

有人发现我遗漏了什么明显的东西吗?

【问题讨论】:

    标签: ruby-on-rails devise routes


    【解决方案1】:

    show.html.erb 视图文件必须存在于app/views/products 目录中。

    注意products(复数)而不是product(单数)。

    【讨论】:

      猜你喜欢
      • 2017-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-09
      • 1970-01-01
      • 1970-01-01
      • 2014-02-18
      • 1970-01-01
      相关资源
      最近更新 更多