Ruby 不显示视图的更新操作

Ruby 不显示视图的更新操作,ruby,ruby-on-rails-3,Ruby,Ruby On Rails 3,我有一个不需要单独显示视图的项目模型。相反,当项目更新时,我希望将用户返回到索引。提交表单编辑项目时,会出现如下错误:No route matches[PUT]“/items/1” 这是路由文件 Order::Application.routes.draw do root to: 'static_pages#home' resources :static_pages resources :customers resources :demands resources :i

我有一个不需要单独显示视图的项目模型。相反,当项目更新时,我希望将用户返回到索引。提交表单编辑项目时,会出现如下错误:
No route matches[PUT]“/items/1”

这是路由文件

Order::Application.routes.draw do

  root to: 'static_pages#home'

  resources :static_pages
  resources :customers
  resources :demands

  resources :items, only: [:new, :create, :destroy, :index, :edit]


end
这是控制器

class ItemsController < ApplicationController

    def index
        @items = Item.all
    end

    def new
        @item = Item.new
    end

    def create
        @item = Item.new(params[:item])
        if @item.save
            flash[:success] = "Item saved!"
            redirect_to items_path
        else
            render new_item_path
        end
    end

    def destroy
        Item.find(params[:id]).destroy
        redirect_to items_path
    end

    def edit
        @item = Item.find(params[:id])
    end

    def update
        @item = Item.find(params[:id])
        if @item.update_attributes(params[:item])
            redirect_to 'items#index'
            flash[:success] = "Item updated!"
        else
            render 'edit'
        end
    end 


end
class ItemsController
这是模型

class Item < ActiveRecord::Base
  attr_accessible :name, :price

  validates :name, presence: true

  VALID_PRICE_REGEX = /^[+-]?[0-9]{1,3}(?:,?[0-9]{3})*\.[0-9]{2}$/
  validates :price, presence: true, format: {with: VALID_PRICE_REGEX}

end
class项
您缺少路由文件中
项目的
更新
操作

resources :items, only: [:new, :create, :destroy, :index, :edit]
应该是

resources :items, only: [:new, :create, :destroy, :index, :edit, :update]
或者更简单地说

resources :items, except: [:show]

啊,当然。我不敢相信我错过了这么简单的事情。非常感谢。