0
0

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 1 year has passed since last update.

Railsフォームビルダー

Posted at

form_withメソッドの使い方

form_withメソッドの使用例
<%= form_with model: @user, url: :registration do |f| %>
  <%= f.label :name, "名前" %>
  <%= f.text_field :email %>
  <%= f.submit "送信" %>
<%= end %>

フォームビルダーに備わっているメソッド
ブロック引数 f はフォームビルダーと呼ばれます。
このオブジェクトのメソッドを呼び出すと、フォーム上に部品が生成されます。先程の例では、
3つのメソッドを用いてボタンを生成しています。

 label・・ラベル
 text_field・・テキスト入力欄
 submit・・・送信ボタン

[フォームビルダー用のメソッドのリスト]
https://api.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?