困っていること
店舗情報を登録するページを作りたいが、上手くいかない。
以下logを確認するとnewアクションまでは呼び出せているが、createアクションが見つからないとエラーが出ている。
しかし、該当コントローラ内にcreateアクションは存在し原因がわからない。
まだrails初学者で、resoucesを使ったルーティングができていないのですが、それが原因でしょうか?
ちなみに、log以外でのエラーは出ておらずview出力まで動いてはいます。
log
1Started GET "/mypage/shop" for 0.0.0.0 at 2019-08-01 07:27:27 +0000 2Processing by ShopsController#new as HTML 3 Rendering shops/new.html.erb within layouts/application 4 Rendered shops/new.html.erb within layouts/application (12.4ms) 5 Rendered shops/_shop-header.html.erb (5.4ms) 6 Rendered shops/_shop-footer.html.erb (0.3ms) 7Completed 200 OK in 58ms (Views: 57.3ms | ActiveRecord: 0.0ms) 8 9Started POST "/mypage/shop" for 0.0.0.0 at 2019-08-01 07:27:29 +0000 10 11AbstractController::ActionNotFound - The action 'create' could not be found for ShopsController:
ソースコード
controller
1class ShopsController < ApplicationController 2end 3 4 def new 5 @shop = Shop.new 6 end 7 8 def create 9 @shop = Shop.new(school_detail_params) 10 11 if @shop.save 12 #保存に成功した時の処理 13 else 14 #保存に失敗した時の処理 15 end 16 end 17 18 private 19 20 def shop_params 21 params.require(:shop).permit(:shop_name, :shop_name_kana, :post_code) 22 end
route
1 get 'mypage/shop' => 'shops#new' 2 post 'mypage/shop' => 'shops#create'
view
1<main> 2 <%= form_with url: mypage_shop_path do |form| %> 3 <div class="groop input-box"> 4 <p class="fs-m">店舗名</p> 5 <%= form.text_field :shop_name, :class => "l" %> 6 </div> 7 8 <div class="groop input-box"> 9 <p class="fs-m">テンポメイ</p> 10 <%= form.text_field :shop_name_kana, :class => "l" %> 11 </div> 12 13 <div class="groop input-box"> 14 <p class="fs-m">郵便番号</p> 15 <%= form.text_field :post_code, :class => "m" %> 16 </div> 17 <% end %>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/02 08:06 編集
2019/08/02 08:24