&tag(Rails/フォーム); *目次 [#zc5cb8b4] #contents *関連ページ [#tbe1b391] *参考情報 [#v2e8a01d] *Tips [#r6205d0d] **データの保存時に空白をnullに変換 [#sb3131d6] -[[mysql - Rails: Force empty string to NULL in the database - Stack Overflow:http://stackoverflow.com/questions/7202319/rails-force-empty-string-to-null-in-the-database]]によると簡単に実行する方法はない? -[[rubiety/nilify_blanks:https://github.com/rubiety/nilify_blanks]]…nifty blanksというgemがあるらしいけど。 **複数Submitボタンが存在するForm [#xd43d26a] -ビュー側 #pre{{ <%= form_tag(operate_url) do %> <%= submit_tag('移動')%> <%= submit_tag('削除', {name: 'delete'})%> <% end %> }} -コントローラー側 #pre{{ if params[:delete] #削除処理 redirect_to(folder_path(@folder), notice: "削除しました") else #通常処理 redirect_to(folder_path(@folder), notice: "移動しました") end }} **2重保存を防ぐ [#d65bc4c1] -Submitを無効化するのではなく、戻る=>保存の2重登録を防ぐ方法。 --[[herval/double_submit_protection:https://github.com/herval/double_submit_protection]] --[[実録!Railsのはまりポイント10選:http://www.slideshare.net/drecom/edgerails2]] --[[browser - Rails: Prevent duplicate inserts due to pressing back button and save again - Stack Overflow:http://stackoverflow.com/questions/4657758/rails-prevent-duplicate-inserts-due-to-pressing-back-button-and-save-again]] -全部同じアイデアでセッションにトークンを保存して、保存時に確認する処理を入れる。しかしかなり古いし、最近の情報はあまり見つからない。より良い方法があるか確認する。 -ちなみにRedmineでも戻る、保存で連続作成できてしまう。何もしないのが定石?