前提・実現したいこと
railsの1対1リレーションがあるフォームを作成しています。
エラーは出ていないのですが、updateが成功していないため、原因を知りたいです。
発生している問題
エラーは出ていないが、updateされずに:editにレンダリングされる. updateが成功すれば、期待通りにリダイレクトするはずです。
controller
1def edit 2 @property = Property.find(params[:id]) 3 end 4 5 def update 6 @property = Property.find(params[:id]) 7 logger.debug(property_params) 8 if @property.update(property_params) 9 flash[:success] = "Profile updated" 10 redirect_to property_path(@property) 11 else 12 render 'edit' 13 end 14 end 15 16 private 17 18 def property_params 19 params.require(:property).permit(:name, property_overview_attributes: [:address, :postal_code, :date_of_build]) 20 end
form
1<%= form_with(model: @property, local: true) do |f| %> 2 3 <div class="form-group"> 4 <%= f.label :name %> 5 <%= f.text_field :name, class: 'form-control' %> 6 </div> 7 8 <%= f.fields_for(:property_overview, local: true) do |i| %> 9 <div class="form-group"> 10 <%= i.label :address %> 11 <%= i.text_field :address, class: 'form-control' %> 12 </div> 13 14 <div class="form-group"> 15 <%= i.label :postal_code %> 16 <%= i.number_field :postal_code, class: 'form-control' %> 17 </div> 18 19 <div class="form-group"> 20 <%= i.label :date_of_build %> 21 <%= i.date_field :date_of_build, class: 'form-control' %> 22 </div> 23 <% end %> 24 <%= f.submit yield(:button_text), class: "btn btn-primary" %> 25<% end %>
log
1Started PATCH "/properties/10" for 172.18.0.1 at 2021-01-13 08:22:29 +0000 2Cannot render console from 172.18.0.1! Allowed networks: 127.0.0.0/127.255.255.255, ::1 3Processing by PropertiesController#update as HTML 4 Parameters: {"authenticity_token"=>"ua3FliJrkPp0pZa2tHECWtJTUWngU3LXEy3T+A6tnHfvIfsf+ybHPXGGNzH/darZeFeEJcsY3EMVzmV8q33KrQ==", "property"=>{"name"=>"kamana", "property_overview_attributes"=>{"address"=>"アップデートできないのはなぜ?", "postal_code"=>"198738", "date_of_build"=>"2021-01-06", "id"=>"10"}}, "commit"=>"Save Changes", "id"=>"10"} 5 [1m[36mUser Load (0.4ms)[0m [1m[34mSELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2[0m [["id", 1], ["LIMIT", 1]] 6 ↳ app/helpers/sessions_helper.rb:9:in `current_user' 7 [1m[36mUserAuthorization Exists? (0.3ms)[0m [1m[34mSELECT 1 AS one FROM "user_authorizations" WHERE "user_authorizations"."user_id" = $1 AND "user_authorizations"."controller" = $2 AND "user_authorizations"."action" = $3 LIMIT $4[0m [["user_id", 1], ["controller", "properties"], ["action", "update"], ["LIMIT", 1]] 8 ↳ app/controllers/application_controller.rb:22:in `check_authorization' 9 [1m[36mProperty Load (0.2ms)[0m [1m[34mSELECT "properties".* FROM "properties" WHERE "properties"."id" = $1 LIMIT $2[0m [["id", 10], ["LIMIT", 1]] 10 ↳ app/controllers/properties_controller.rb:30:in `update' 11[31mUnpermitted parameter: :id[0m 12 [1m[35m (0.5ms)[0m [1m[35mBEGIN[0m 13 ↳ app/controllers/properties_controller.rb:32:in `update' 14 [1m[36mPropertyOverview Load (0.6ms)[0m [1m[34mSELECT "property_overviews".* FROM "property_overviews" WHERE "property_overviews"."property_id" = $1 LIMIT $2[0m [["property_id", 10], ["LIMIT", 1]] 15 ↳ app/controllers/properties_controller.rb:32:in `update' 16 [1m[36mPropertyOverview Destroy (0.6ms)[0m [1m[31mDELETE FROM "property_overviews" WHERE "property_overviews"."id" = $1[0m [["id", 10]] 17 ↳ app/controllers/properties_controller.rb:32:in `update' 18 [1m[36mProperty Destroy (0.9ms)[0m [1m[31mDELETE FROM "properties" WHERE "properties"."id" = $1[0m [["id", 10]] 19 ↳ app/controllers/properties_controller.rb:32:in `update' 20 [1m[36mPropertyOverview Exists? (0.5ms)[0m [1m[34mSELECT 1 AS one FROM "property_overviews" WHERE "property_overviews"."address" = $1 LIMIT $2[0m [["address", "アップデートできないのはなぜ?"], ["LIMIT", 1]] 21 ↳ app/controllers/properties_controller.rb:32:in `update' 22 [1m[35m (0.4ms)[0m [1m[31mROLLBACK[0m 23 ↳ app/controllers/properties_controller.rb:32:in `update' 24 Rendering properties/edit.html.erb within layouts/application 25 Rendered layouts/_side.html.erb (Duration: 0.2ms | Allocations: 68) 26 Rendered shared/_error_message.html.erb (Duration: 0.1ms | Allocations: 5) 27 Rendered properties/_form.html.erb (Duration: 5.0ms | Allocations: 1381) 28 Rendered properties/edit.html.erb within layouts/application (Duration: 8.7ms | Allocations: 1584) 29[Webpacker] Everything's up-to-date. Nothing to do 30 Rendered layouts/_rails_default.html.erb (Duration: 43.6ms | Allocations: 13894) 31Completed 200 OK in 133ms (Views: 57.1ms | ActiveRecord: 14.2ms | Allocations: 38662)
createやdestroyなど、他のアクションは期待通りに動いています。
足りない情報があれば教えていただきたいです。
個人的には、logに含まれる
Unpermitted parameter: :id
がきになるのですが、これは何者でしょうか?
原因がわかれば、お力添えいただきたいです。よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。