No route matches [POST]エラーについて
現在PCの構成部品を選択し、そのPCの名前と構成部品をPCテーブルに登録するアプリを作成しています。
登録画面(app/view/pc/new.html.haml)の作成は完了しましたが、submitボタンを押すと「No route matches [POST] "/pc/new"」のルーティングエラーが発生します。
rails routesでルーティングを確認したところPOSTはあるので、なぜこのエラーが出るかわかりません。
どのように修正すればよろしいでしょうか。
よろしくお願いします。
app/view/pc/new.html.haml .new .content = form_with model: @pcs, local:true, class:"content_wrapper" do |f| .pc .name = f.text_field :name, class:"pc_name", placeholder: "PC名", maxlength: "20",required: true .cpu = f.collection_select :cpu_id, Cpu.all.order(name: :asc), :id, :name .mother_board = f.collection_select :mother_board_id, MotherBoard.all.order(name: :asc), :id, :name .memory = f.collection_select :memory_id, Memory.all.order(name: :asc), :id, :name .videocard = f.collection_select :videocard_id, Videocard.all.order(name: :asc), :id, :name .pc_case = f.collection_select :pc_case_id, PcCase.all.order(name: :asc), :id, :view_name_and_color .power_unit = f.collection_select :power_unit_id, PowerUnit.all.order(name: :asc), :id, :name .ssd = f.collection_select :ssd_id, Ssd.all.order(name: :asc), :id, :name .cpu_cooler = f.collection_select :cpu_cooler_id, CpuCooler.all.order(name: :asc), :id, :name .private %input{name: "private", type: "checkbox", value: "1"} %label{for: "private"} 公開する .submit = f.submit :name, class:"content__wrapper__confirmation__button", value: "確認"
rails routes Prefix Verb URI Pattern pc_index GET /pc(.:format) pc#index POST /pc(.:format) pc#create new_pc GET /pc/new(.:format) pc#new edit_pc GET /pc/:id/edit(.:format) pc#edit pc GET /pc/:id(.:format) pc#show PATCH /pc/:id(.:format) pc#update PUT /pc/:id(.:format) pc#update DELETE /pc/:id(.:format) pc#destroy cpu_index GET /cpu(.:format) cpu#index cpu GET /cpu/:id(.:format) cpu#show mother_board_index GET /mother_board(.:format) mother_board#index mother_board GET /mother_board/:id(.:format) mother_board#show memory_index GET /memory(.:format) memory#index memory GET /memory/:id(.:format) memory#show videocard_index GET /videocard(.:format) videocard#index videocard GET /videocard/:id(.:format) videocard#show pc_case_index GET /pc_case(.:format) pc_case#index pc_case GET /pc_case/:id(.:format) pc_case#show power_unit_index GET /power_unit(.:format) power_unit#index power_unit GET /power_unit/:id(.:format) power_unit#show ssd_index GET /ssd(.:format) ssd#index ssd GET /ssd/:id(.:format) ssd#show cpu_cooler_index GET /cpu_cooler(.:format) cpu_cooler#index cpu_cooler GET /cpu_cooler/:id(.:format) cpu_cooler#show root GET / top#index rails_service_blob GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show rails_blob_representation GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show rails_disk_service GET /rails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show update_rails_disk_service PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create
app/controller/pc_controller.rb class PcController < ApplicationController before_action :authenticate_user!, except: [:index,:show] def index @pc = Pc.all end def show @pc = Pc.find(params[:id]) end def new @pc = Pc.new end def create @pc = Pc.new(pc_params) respond_to do |format| if @pc.save format.html { redirect_to @pc, notice: '作成成功' } format.json { render :show, status: :created, location: @pc } else format.html { render :new } end end end def edit @pc = Pc.find(params[:id]) if current_user.id == @pc.user.id else redirect_to pc_path(@pc) end end def update @pc = Pc.find(params[:id]) if @pc.update(pc_params) redirect_to pc_path(@pc) else render :edit end end def destroy pc = Pc.find(params[:id]) unless pc.destroy render :show end end end
config/routes.rb Rails.application.routes.draw do root 'top#index' devise_for :users, :controllers => { :registrations => 'users/registrations', :sessions => 'users/sessions' } devise_scope :user do get "user/:id", :to => "users/registrations#detail" get "signup", :to => "users/registrations#new" get "login", :to => "users/sessions#new" get "logout", :to => "users/sessions#destroy" end resources :pc, only: [:index, :create, :new, :show, :edit, :update, :destroy] resources :cpu, only: [:index, :show] resources :mother_board, only: [:index, :show] resources :memory, only: [:index, :show] resources :videocard, only: [:index, :show] resources :pc_case, only: [:index, :show] resources :power_unit, only: [:index, :show] resources :ssd, only: [:index, :show] resources :cpu_cooler, only: [:index, :show]
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。