我正在尝试制作一个允许用户创建销售的小应用程序。有用户模型产品模型和照片模型。一个用户有很多产品,产品有很多照片。但由于某种原因,在我尝试创建产品页面后,我收到了这个错误。
路由错误
No route matches [PUT] "/products"
路线.rb
resources :products
resources :photos
产品控制器
def new
@product = Product.new
@photo = Photo.new
end
def create
@product = current_user.products.build(params[:product])
@photo = current_user.photos.new(params[:photo])
if @product.save && @photo.save
@photo.product_id = @product.id
render "show", :notice => "Sale created!"
else
render "new", :notice => "Somehting went wrong!"
end
end
def show
@product = Product.find(params[:id])
end
新产品页面 (HAML)
%h1
create item
= form_for @product,:url => products_path, :html => { :multipart => true } do |f|
%p
= f.label :name
= f.text_field :name
%p
= f.label :description
= f.text_field :description
= f.text_field :ship_price
%p
= fields_for :photo, :html => {:multipart => true} do |fp|
= fp.file_field :image
%p.button
= f.submit
耙路线
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
PUT /products/:id(.:format) products#update
DELETE /products/:id(.:format) products#destroy
如果我已经做了资源,这不应该工作吗:产品!?