お世話になります。
タイトルの通り、railsでnewのviewにある[登録する]ボタンを押下してもcreateに飛んで処理ができない状態です。
エラー内容は
ActionController::RoutingError (No route matches [POST] "/schcols/10001/%E8%99%BB%E7%94%B0%E9%AB%98%E6%A0%A1/new")
となっており、POSTアクションでcreate処理をしたいのですが、newに飛んでしまっている状態です。
以下設定になります。
new.html.slim
rails
1 2.text-muted.h4 3 = form_with model: @schcols, url: schcols_new_path do |f| 4 .ul.list-inline.form-group.py-2.row 5 .li.list-inline-item.text-right.col-md-2 6 = f.label :sch_id 7 .li.list-inline-item.col-md-2 8 = f.text_field :sch_id, class: 'form-control', id: 'sch_id', value: @schmaster_schid 9 略 10 .ul.list-inline.form-group.py-2.row 11 .li.list-inline-item.text-right.col-md-2.align-self-center 12 = f.label :remarks2 13 .li.list-inline-item.col-md-9 14 = f.text_area :remarks2, row:4, class: 'form-control', id: 'remarks2' 15 = f.submit nil, class: 'btn btn-primary btn-lg'
schcols_contoroller.rb
ruby
1 2 def new 3 @schcols = Schcol.new 4 @schmaster_schname = params[:name] 5 @schmaster_schid = params[:sch_id] 6 end 7 8 def create 9 schcol = Schcol.new(schcols_params) 10 schcol.save! 11 redirect_to schcols_newindex_path, notice: "新規登録しました!" 12 end 13 private 14 def schcols_params 15 params.require(:schcol).permit(:sch_id, :sch_year, :classification, :item_id, :sch_col1, :sch_col2, :sch_col3, :sch_col4, :sch_col5, :sch_col6, :remarks1, :remarks2) 16 end 17
routes.rb
ruby
1Rails.application.routes.draw do 2 controller :schcols do 3 resources :schcols, only: [:index, :create, :update, :destroy] 4 post '/schcols/import', to: 'schcols#import' 5 get '/schcols/:sch_id/:name/new', to: 'schcols#new', as: 'schcols_new' 6 get '/schcols/newindex', to: 'schcols#newindex', as: 'schcols_newindex' 7 get '/schcols/:id/:name/edit', to: 'schcols#edit', as: 'schcols_edit' 8 get '/schcols/:sch_id/:name', to: 'schcols#show', as: 'schcols_show' 9 end 10end
newのview画面にはsubmitボタンに[登録する]と出ているので、create処理できると思ってたのですが…。
初歩的な基本がわかっていないと思います。
ご教授お願いいたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/02/19 02:30