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 3 years have passed since last update.

ダイエット+食品管理アプリ構築の道程(4)

Posted at

migrate後のテーブルです。

cookingsテーブル(親)
20210625-191123.png

fridgesテーブル(子)
20210625-191407.png

####attr_acccessor
#####フィールド名を設定します。
formタグに含まれるテキスト
inputタグ内部にあるid属性・name属性・placeholder属性のテキスト情報

(参考)コンパイル前
<%= form_with model: @user do |f| %>
  <%= f.label :name, '名前' %>
  <%= f.text_field :name %>
  <%= f.submit "送信" %>
<% end %>

コンパイルされると

((参考)今回の場合はデータが既に存在する場合で設定)
<form action="/users" accept-charset="UTF-8" data-remote="true" method="post">
  <label for="user_name">名前</label>
  <input type="text" name="user[name]" id="user_name" />
  <input type="submit" name="commit" value="送信" data-disable-with="送信" />
</form>

(参考)

:name→ label for="user_name"
:name→ input id="user_name"
:name→ input name="user[name]"

*頭にuserがつくのは@userにuserモデルのインスタンスを格納しているため

(参考)

オプション 入力エリアのname属性 ストロングパラメータ
model: @user name="user[email]" params.require(:user).permit(:email)

https://applis.io/posts/rails-design-pattern-form-objects

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?