編集画面を作成しているのですが、編集した情報が保存されません。
保存されたら最初の画面に戻るという設定をしていて、それは機能するのですが、変更が反映されないです。
home_controller
1def edit 2 @aquarium = Aquarium.find(params[:id]) 3 end 4 def update 5 @aquarium = Aquarium.find(params[:id]) 6 if @aquarium.save 7 redirect_to action: "index" 8 else 9 redirect_to action: "edit" 10 end 11 end
edit.html.erb
1<%= form_for(@aquarium, url:{controller:'home', action:'update'}) do |f| %> 2<div class="field"> 3 <%= f.label :image %> 4 <%= f.file_field :image %> 5 <br> 6 <%= f.label :title %> 7 <%= f.text_field :title %> 8 <br> 9 <%= f.label :content %> 10 <%= f.text_field :content %> 11 <br> 12 <%= f.label :point %> 13 <%= f.text_field :point %> 14 <br> 15 <%= f.label :prefacture %> 16 <%= f.text_field :prefacture %> 17</div> 18<div class="action"> 19 <%= f.submit %> 20</div> 21<% end %> 22
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。