いつもお世話になります。
現在投稿フォームを下記コードのように書いております。
送信を押してPOSTした際のストロングパラメータなのですがよく
params.require(:user).permit(:name, :email)
というような表記を見ます。
普通にPOSTすると
{"utf8"=>"✓",
"authenticity_token"=>"sbS3E・・(略)",
"name"=>"test",
"email"=>"test@test",
"commit"=>"送信"}
となると思うのですが、
params.require(:user).permit(:name, :email)
で受け取るためには
{"utf8"=>"✓",
"authenticity_token"=>"sbS3E・・(略)",
"user"=>{"name"=>"test","email"=>"test@test"},
"commit"=>"送信"}
とすることが必要という解釈でよろしいでしょうか。
また、このようにPOSTするにはどのようにすればよろしいのでしょうか。
不勉強で申し訳ございませんが、ご教示のほどお願いいたします。
Ruby
1 2# コントローラー側 3 4 5private 6 def post_params 7 params.require(:user).permit(:name, :email) 8 end 9 10 11# ビュー側 12<%= form_with(model: @xxxx, local: true, html: {id: 'inform_save', class: 'form', autocomplete: 'off'}) do |f| %> 13 <div class="field"> 14 <%= f.label :name, "名前" %> 15 <%= f.text_field :name, size: 25, value: "", id: "name", class: "name" %> 16 </div> 17 <div class="field"> 18 <%= f.label :email, "email" %> 19 <%= f.text_field :email, size: 25, value: "", id: "email", class: "email" %> 20 </div> 21 <div class="actions"> 22 <%= f.submit '送信' %> 23 </div> 24<% end %> 25 26
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。