Railsでアプリを作っているのですがform_for で値を受け取る時にエラーが出ます。エラーの意味もわからずどう対処して良いかわかりません。
おそらくコントローラーの書き方がおかしいのではないかと思います。
よろしくお願いいたします
NoMethodError in TimetablesController#create undefined method ` ' for #<TimetablesController:0x00007f26840ba1b0> Extracted source (around line #11): 9 10 11 12 13 14 def create @timetable = Timetable.new(timetable_params) if @timetable.save flash[:success] = "ご予約ありがとうございます" render root_path Rails.root: /home/ec2-user/environment/portfolio Application Trace | Framework Trace | Full Trace app/controllers/timetables_controller.rb:11:in `create' Request Parameters: {"utf8"=>"✓", "authenticity_token"=>"6SuUpn3FB+8AclGmsnDVPdb9k3rn3/e9aAS/cVkOCpLgi67AIiOqkkZIBknxp2IGpTNA8LgOdgaaZuR9zgX89w==", "timetable"=>{"NOP"=>"1", "time"=>"123"}, "commit"=>"投稿する"} Toggle session dump Toggle env dump Response Headers: None
controller
1class TimetablesController < ApplicationController 2 def timetable_index 3 @timetables = Timetable.all 4 end 5 6 def new 7 @timetable = Timetable.new 8 end 9 10 def create 11 @timetable = Timetable.new(timetable_params) 12 if @timetable.save 13 flash[:success] = "ご予約ありがとうございます" 14 render root_path 15 else 16 flash[:success] = "申し訳ございません。予約を受け付けられませんでした" 17 render root_path 18 end 19 end 20 21 def show 22 end 23 24 def destroy 25 end 26 27 private 28 def timetable_params 29 params.require(:timetable).permit(:NOP, :time) 30 end 31end 32
view
1<h1>投稿フォーム</h1> 2<%= form_for @timetable do |f| %> 3 <p> 4 <%= f.label :NOP, "NOP" %><br> 5 <%= f.text_field :NOP %> 6 </p> 7 <p> 8 <%= f.label :time, "time" %><br> 9 <%= f.text_area :time %> 10 </p> 11 <p> 12 <%= f.submit "投稿する"%> 13 </p> 14<% end %>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/02/15 10:11
2020/02/15 10:30