Railsで開発しています。
form_for を使用し新規でデータを作成しようとしているのですがうまく行きません。。。
formにデータが渡されていないようです。。。
よろしくお願いします。
ruby
1Rails.application.routes.draw do 2 root 'players#index' 3 resources :players 4end
ruby
1class Player < ApplicationRecord 2end 3
ruby
1class PlayersController < ApplicationController 2 def index 3 end 4 5 def new 6 @player = Player.new 7 # debugger 8 end 9 10 def create 11 @player = Player.new(paramas_player) 12 13 @player.save 14 15 # debugger 16 end 17 18 def show 19 20 end 21 22 def edit 23 24 end 25 26 def delete 27 28 end 29 30 private 31 32 def paramas_player 33 params.require(:player).permit(:name, :sex, :number, :hand, :position, :story) 34 end 35end 36
erb
1<section class="bs-docs-section"> 2 <div class="row"> 3 <div class="col-lg-12"> 4 <div class="page-header"> 5 <h1 id="forms">Forms</h1> 6 </div> 7 </div> 8 </div> 9 10 <div class="row"> 11 <div class="col-lg-6"> 12 <div class="bs-component"> 13 <form> 14 <fieldset> 15 <legend>Legend</legend> 16 <div class="form-group"> 17 <%= form_for(@player, url: { controller: 'players', action: 'create'}) do |f| %> 18 19 <%= f.label :name %> 20 <%= f.text_field :name, { class: 'form-control' } %> 21 22 <%= f.label :sex %> 23 <%= f.select :sex, [['男', '男'], ['女', '女']], prompt: '選択してください', class: 'custom-select' %> 24 25 <%= f.label :number %> 26 <%= f.text_field :number, { class: 'form-control'} %> 27 28 <%= f.label :hand %> 29 <%= f.select :hand, [['右投右打', '右投右打'], ['右投左打', '右投左打'], ['右投両打', '右投両打'], 30 ['左投左打', '左投左打'], ['左投右打', '左投右打'], ['左投両打', '左投両打']], prompt: '選択してください' %> 31 32 <%= f.label :position %> 33 <%= f.select :position, [['投手', '投手'], ['捕手', '捕手'], ['一塁手', '一塁手'], ['二塁手', '二塁手'], ['三塁手', '三塁手'], ['遊撃手', '遊撃手'], 34 ['左翼手', '左翼手'], ['中堅手', '中堅手'], ['右翼手', '右翼手']], { prompt: '複数選択可'} , { class: 'form-control' } %> 35 36 <%= f.label :story %> 37 <%= f.text_field :story, { class: 'form-control'} %> 38 39 <%= f.submit :登録, class: 'btn btn-primary' %> 40 <%# <% debugger %> %> 41 <% end %> 42 43 44 なぜかcreateアクションが反応しない 45 46 <%= debug(params) if Rails.env.development? %> 47 </fieldset> 48 </form> 49 </div> 50 </div> 51 </div> 52 </section>
値を入力し登録ボタンを押した段階

回答4件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/24 02:48