1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

(初学者) [Rails6] form_with に classを追記する

Posted at

bootstrapを導入してからレコードの編集も新規追加もできなくなってしまった。
→ 原因は、フォームのところで<form>タグと<%= form_with %>が重複していたから。

edit.html.erb
<form class="form-horizontal" >         ← ここと
  <%= form_with model: @article do |form| %>
    <%= form.text_field :title %>
    <%= form.submit 'Update' %>
  <% end %>
</form>                      ← ここを消すと治った。

では classはどこに書けばよいのか。

form_with<%= %>内にclassを書きたい。
doの手前に書く。

edit.html.erb
<%= form_with model: @article, class: "form-horizontal" do |form| %>

参考:2.2 Binding a Form to an Object

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?