ユーザーがセールを作成できる小さなアプリを作ろうとしています。ユーザーモデルの商品モデルと写真モデルがあります。ユーザーには多くの製品があり、製品には多くの写真があります。しかし、何らかの理由で製品ページを作成しようとすると、このエラーが発生します。
ルーティング エラー
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
既に resources:products を実行している場合、これは機能しないはずです!?