railsでアプリを作っていますがupdateで、編集したものを更新しようとしてもエラーは出ないのですが更新されません
form_withを使用して,new.html.erbではurl指定、edit.html.erbではmodelを指定しているのですが、これがいけないのでしょうか?
edit.html.erb
edit.html.erb
1 2 <div class="contents row"> 3 <%= form_with(model: @tweet,local: true) do |f|%> 4 <p>大会選択</p> 5 <%=f.select :tournament_id, options_for_select( @category_parent_array.map{|c| [c[:name], c[:id]]}),{include_blank: "選択してください"}, { class: "parent_category_box", id: "parent_category"}%> 6 <p>高校A 得点</p> 7 <%= f.select :school_a_score, options_for_select((1..50).to_a) %> 8 <p>高校B 得点</p> 9 <%= f.select :school_b_score, options_for_select((1..50).to_a) %> 10 <%= f.text_field :title_info,placeholder: "サブタイトル",class: "game_record",value: "#{@tweet.title_info}" %> 11 <%= f.text_area :text, cols: 30 ,rows: 10,value: "#{@tweet.text}" %> 12 <%= f.label :image, class: "form-image" do %> 13 <% end %> 14 <%=f.submit value: "SENT",class: "game_record"%>
作成時のフォーム new.html.erbのform_withは以下です
<%= form_with url: tweets_path,local: true do |f| %>
コントローラー
def edit @tweet = Tweet.find(params[:id]) end def update @tweet.update(tweet_params) if @tweet.user_id == current_user.id || current_user.admin redirect_to action: :show end def tweet_params params.permit(:image,:text,:title_info,:school_a_score,:school_b_score,:school_a_id,:school_b_id,:tournament_id).merge(user_id: current_user.id) end //:school_a_id :school_b_id :tournamentは他モデルとアソシエーションを組んで参照しています //:school_a_id :school_b_idはjsファイルから送信しています
ためにしeditページをform_tagで書き換えてみると更新できました
edit.html.erbが違うのかと思います
追記 参考
school_a_id
school_b_id
のviewは以下になります
childSelectHtml = `<p>高校A</p> <select name="school_a_id" class="tournament_select_child" id="children_category"> <option value="" data-category="" >選択してください</option> ${insertHTML}</select>` $(".school").append(childSelectHtml) childSelectHtml2 = `<p>高校B</p> <select name="school_b_id" class="tournament_select_child" id="children_category"> <option value="" data-category="" >選択してください</option> ${insertHTML}</select>` $(".school2").append(childSelectHtml2)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/09/26 13:41
2020/09/26 13:43
2020/09/26 14:08
2020/09/26 14:13
2020/09/26 14:26
2020/09/26 14:39
2020/09/26 14:48 編集
2020/09/26 15:34
2020/09/26 21:46
2020/09/27 00:15
2020/09/27 00:21