前提・実現したいこと
prototypeの部屋を作りたい
しかし保存しようとするとル-ティングエラーが出てしますので
それをどうにかしたいです
発生している問題・エラーメッセージ
ruby on railsでの作成途中でおきました
エラーメッセージ
https://gyazo.com/9ce4c70f76cd8fc12de4daccd7d73cd8
エラー文です
Routing Error No route matches [POST] "/prototypes/new" Rails.root: /Users/kamiyaryota/Desktop/projects/protospace-31035 Application Trace | Framework Trace | Full Trace Routes Routes match in priority from top to bottom Request Parameters: {"authenticity_token"=>"iMFsxHjUGk9ZLXCQb0jmase2O/KjhjD9LuLYI7ZTQ3rC1crNukf4EkjDG3EY5WBew32FEqq/htakRgtzcsmUgA==", "title"=>"aaaa", "catct_copy"=>"aaaa", "concept"=>"aaaa", "commit"=>"保存する"} Toggle session dump Toggle env dump Response Headers: None
該当コード
routes.rbです
ruby
1Rails.application.routes.draw do 2 devise_for :users 3 root to: "prototypes#index" 4 resources :users, only: [:new, :edit, :update,] 5 resources :prototypes, only: [:new, :create] 6 7 devise_scope :user do 8 get '/users/sign_out' => 'devise/sessions#destroy' 9 end 10 11end 12
コントローラー.rbです
ruby
1class PrototypesController < ApplicationController 2 3 def index 4 5 end 6 7 def new 8 @prototype = Prototype.new 9 end 10 11 def create 12 @prototype = Prototype.create(prototype_params) 13 if @prototype.save 14 redirect_to root_path 15 else 16 render :new 17 end 18 end 19 20 21 22 23 private 24 def prototype_params 25 params.require(:prototype).permit(:title, :catct_copy, :concept).merge(user_id: current_user.id) 26 end 27 28end
model.rbです
ryby
1class Prototype < ApplicationRecord 2has_many :comments 3belongs_to :user 4 5has_one_attached :image 6 7validates :title, presence: true 8validates :catct_copy, presence: true 9validates :concept, presence: true 10validates :image, presence: true 11 12end
投稿ページです
html
1<div class="main"> 2 <div class="inner"> 3 <div class="form__wrapper"> 4 <h2 class="page-heading">新規プロトタイプ投稿</h2> 5 <%= render partial: "form" %> 6 </div> 7 </div> 8</div>
*部分テンプレートのコードです、ファイル名は_form_html_rbです*
html
1<%= form_with model: @prototype, local: true do |f|%> 2 <div class="field"> 3 <%= f.label :title, "プロトタイプの名称" %><br /> 4 <%= f.text_field :title %> 5 </div> 6 7 <div class="field"> 8 <%= f.label :catct_copy, "キャッチコピー" %><br /> 9 <%= f.text_area :catct_copy, class: :form__text %> 10 </div> 11 12 <div class="field"> 13 <%= f.label :concept, "コンセプト" %><br /> 14 <%= f.text_area :concept, class: :form__text %> 15 </div> 16 17 <div class="field"> 18 <%= f.label :image, "プロトタイプの画像" %><br /> 19 <%= f.file_field :image %> 20 </div> 21 22 <div class="actions"> 23 <%= f.submit "保存する", class: :form__btn %> 24 </div> 25<% end %>
routesの一覧です
Prefix Verb URI Pattern Controller#Action new_user_session GET /users/sign_in(.:format) devise/sessions#new user_session POST /users/sign_in(.:format) devise/sessions#create destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy new_user_password GET /users/password/new(.:format) devise/passwords#new edit_user_password GET /users/password/edit(.:format) devise/passwords#edit user_password PATCH /users/password(.:format) devise/passwords#update PUT /users/password(.:format) devise/passwords#update POST /users/password(.:format) devise/passwords#create cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel new_user_registration GET /users/sign_up(.:format) devise/registrations#new edit_user_registration GET /users/edit(.:format) devise/registrations#edit user_registration PATCH /users(.:format) devise/registrations#update PUT /users(.:format) devise/registrations#update DELETE /users(.:format) devise/registrations#destroy POST /users(.:format) devise/registrations#create root GET / prototypes#index new_user GET /users/new(.:format) users#new edit_user GET /users/:id/edit(.:format) users#edit user PATCH /users/:id(.:format) users#update PUT /users/:id(.:format) users#update prototypes POST /prototypes(.:format) prototypes#create new_prototype GET /prototypes/new(.:format) prototypes#new
回答1件
あなたの回答
tips
プレビュー