前提・実現したいこと
Rails初心者です。
accepts_nested_attributes_forでネストさせキーがビューに出力できません。
binding.pryで確認したparamsには入っているのですが、upadateアクションが働かないので、お分かりになる方がいらっしゃったらご回答いただけると非常に助かります。
発生している問題・エラーメッセージ
accepts_nested_attributes_forでネストさせたキーが出力できない
model
user.rb has_one :profile, dependent: :destroy accepts_nested_attributes_for :profile profile.rb belongs_to :user, optional: true
mypages/edition.html.haml
.wrapper = render 'shared/header' = render 'shared/exhibit-btn' .wrapper-mypage .container-mypage = render "shared/sidebar" .chapter .chapter__container %h2.chapter__container__head プロフィール = form_for(current_user, method: :patch) do |f| %input{name: "__csrf_value", type: "hidden", value: "e20dfc21ec93262f69196fe5a8366c8435d61548623e402c57f6f7f298596bf63aa4e7667fc88a67d1d198661496da48f6178a44b45174307897a0dbb04b59e6c"} .setting-profile-icon %figure = image_tag "//static.mercdn.net/images/member_photo_noimage_thumb.png", height: "60", width: "60" = f.text_field :nickname,class:"setting-profile-icon__input",type: "text", value: "#{current_user.nickname}" .setting-profile-content = f.fields_for :profile do |p| = p.text_area :profile,class:"setting-profile-content__textarea", placeholder: "例)こんにちは☆ ご覧いただきありがとうございます!かわいいものやきれいめオフィスカジュアル中心に出品しています。服のサイズは主に9号です。気持ちよくお取引できるよう心がけていますので、商品や発送方法などご質問がありましたらお気軽にどうぞ♪",value: "#{current_user.profile.profile}" = f.submit "変更する", {controller: :users,action: :update,user_id: current_user.id,class: "btn-default"}
users_controller
class UsersController < ApplicationController before_action :authenticate_user! def edit @user = User.find(current_user.id) end def update current_user.update(user_params) redirect_to edit_user_path end private def user_params params.require(:user).permit(:nickname, profile_attributes: [:profile,:id]) end end
updateアクション下でデバックしたparamsの情報
<ActionController::Parameters {"utf8"=>"✓", "_method"=>"patch", "authenticity_token"=>"Q6kuEd4gvmVRkCvSZQ01U+xnLIGCAAoGAwXNzRlzJHntJIHFfgF8xIBUVPqcwgMMfhRIG4jfxtN3bezXzNg2iQ==", "__csrf_value"=>"e20dfc21ec93262f69196fe5a8366c8435d61548623e402c57f6f7f298596bf63aa4e7667fc88a67d1d198661496da48f6178a44b45174307897a0dbb04b59e6c", "user"=>{"nickname"=>"hはあff", "profile_attributes"=>{"profile"=>"fcccccccccccccccccccccccccccccccc", "id"=>"1"}}, "commit"=>"変更する", "controller"=>"users", "action"=>"update", "id"=>"1"} permitted: false>
補足情報(FW/ツールのバージョンなど)
Ruby version 2.5.1
Rails version 5.2.3
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。