36
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

 【Rails7】保存ボタン(submit)をフォームの外にしたい

Last updated at Posted at 2024-06-29

はじめに

「保存ボタン(submit)をフォームの外にしたい😭」ということがありました。

開発環境

  • Rails 7.0.4.2
  • ruby 3.1.4

コード

button_tagを使用して、フォームの外側に保存ボタンを作成しました!

-----------------------------------------------------------<br>

<%= button_tag("保存", type: "submit", form: "post_form") %>

<br>-----------------------------------------------------------

<%= form_with(model: post, id: "post_form") do |form| %>
  <div>
    <%= form.label :title, style: "display: block" %>
    <%= form.text_field :title %>
  </div>

  <div>
    <%= form.label :content, style: "display: block" %>
    <%= form.text_area :content %>
  </div>
<% end %>

保存される様子

画面収録-2024-06-30-7.23.30.gif

無事に保存されました!

36
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
36
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?