【結論】アクションを実行するかしないかの違い
xxx_controller.rb
def create
message = Message.new(message_params)
if message.save
redirect_to :new
else
render :new
end
end
このようなcreateアクションがあります。
・save
が成功した場合はnewアクションが実行され
、一度ページがリセットされnewのページが表示されます。
・save
が失敗した場合はnewアクションを通さず
、入力された情報はそのままにnewのページが表示されます。
保存が成功したらフォームに情報を残しておく必要はありませんよね。
保存が失敗したらエラーメッセージを表示するなどして、入力情報のエラー部分のみを変更してもらいましょう。
参考
ではまた!