こんにちは。
プログラミング初心者です。
現在、Railsでフリマサイトを作成しておりまして、
出品した商品の編集ができません。
#エラー内容
No route matches [PATCH] "/users/products"
#products_controller.rb
ruby
1def edit 2 #ユーザーの商品詳細編集 3 @product = Product.find(params[:id]) 4 end 5 6 def update 7 upload_file = params[:product][:image1] 8 #投稿画像がない場合 9 if upload_file.present? 10 #画像のファイル名取得 11 upload_file_name1 = upload_file.original_filename 12 output_dir = Rails.root.join('public', 'images') 13 output_path = output_dir + upload_file_name1 14 File.open(output_path, 'w+b') do |f| 15 f.write(upload_file.read) 16 end 17 @product.image1 = upload_file_name1 18 end 19 if @product.save 20 flash[:success] = '商品情報を更新しました' 21 redirect_to top_path and return 22 else 23 flash[:danger] = '更新に失敗しました' 24 redirect_to edit_product_path and return 25 end 26 end
#routes.rb
Ruby
1Rails.application.routes.draw do 2 3 root 'products#index', as: :root 4 5 post '/', to: 'products#index' 6 7 post '/', to: 'products#create' 8 9 get 'users/profiles', to: 'users#top', as: :top 10 11 get 'users/sign_up', to: 'users#new', as: :sign_up 12 13 post 'users/sign_up', to: 'users#create' 14 15 get 'users/sign_in', to: 'users#sign_in', as: :sign_in 16 17 post 'users/sign_in', to: 'users#sign_in_process' 18 19 get 'users/sign_out', to: 'users#sign_out', as: :sign_out 20 21 get 'users/products', to: 'users#products', as: :user_products 22 23 post 'users/products', to: 'products#create' 24 25 get '/users/products/new', to: 'products#new', as: :new_product 26 27 get '/users/products/:id', to: 'users#product', as: :user_product 28 29 delete '/users/products/:id/', to: 'products#destroy' 30 31 get '/users/products/:id/edit', to: 'products#edit', as: :edit_product 32 33 patch '/users/products/:id/edit', to: 'products#update' 34 35 get '/users/likes', to: 'users#likes', as: :user_likes 36 37 get '/users/profiles/edit', to: 'users#edit', as: :edit_user 38 39 post '/users/profiles/edit', to: 'users#update' 40 41 get '/markets/:id', to: 'products#show', as: :product 42 43 get '/markets/:id/payment', to: 'products#payment', as: :payment 44 45 get '/markets/:id/payment_complete', to: 'products#payment_complete', as: :payment_complete 46 47 # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html 48end
似たような質問やサイトを参考にしましたが、解決できません。
説明不足で申し訳ございませんが、何卒よろしくお願い致します。
回答2件
あなたの回答
tips
プレビュー