Home>
The value of the update action has not changed and no error has occurred.
create works fine.
Corresponding source code

views/searches/edit.html.erb

<% = form_with (model: @search, local: true) do | f |%>      <% = f.label: postal_code, "zip code"%>      <% = f.text_field: postal_code, class: "search_form"%>      <% = f.label: address1, "prefecture"%>      <% = f.text_field: address1, class: "search_form"%>      <% = f.label: address2, "city"%>      <% = f.text_field: address2, class: "search_form"%>      <% = f.label: address3, "town area"%>      <% = f.text_field: address3, class: "search_form"%>      <% = f.label: building_name, "building name"%>      <% = f.text_field: building_name, class: "search_form"%>      <% = f.label: phone_number, "phone number"%>      <% = f.text_field: phone_number, class: "search_form"%>      <br>      <% = f.submit class: "button is-warning"%>    <% end%>

config/routes.rb

Rails.application.routes.draw do
  get'searches', to: "searches # search"
  mount RailsAdmin :: Engine =>'/ admin', as:'rails_admin'
  devise_for: users, controllers: {
   omniauth_callbacks:'users/omniauth_callbacks',
   registrations:'users/registrations'
  }
  get'homes/index'
  resources: homes, only: [: index]
  root to:'home # index'
  resources: users
  resources: attendances
  resources: daytimes
  resources: restaurants, only: [: index,: show]
  resources: searches do
    collection doget'search'
    end
  end
  namespace: admin do
    resources: restaurants, only: [: index,: new,: create,: show,: edit,: destroy]
  end
end


controllers/searches_controller.rb

class SearchesController
What I tried

I applied binding.pry in the update action

[2] pry (#)>Search.find (params [: id])
CACHE Search Load (0.0ms) SELECTsearches. * FROMsearchesWHEREsearches..id= 1 LIMIT 1 [["id", 1], ["LIMIT", 1]]
↳ (pry): 15: in ʻupdate'
=># id: 1,
user_id: 3,
postal_code: "5420076",
address1: "Osaka",
address2: "Chuo-ku, Osaka",
address3: "Namba 5-1 -60",
building_name: "Namba Skyo 15th floor",
phone_number: "0503187-577",
created_at: Mon, 26 Oct 2020 11:19:35 JST +09: 00,
updated_at: Mon, 26 Oct 2020 11:19:35 JST +09: 00>
[3] pry (#)>params
=>"patch", "authenticity_token" =>"3C + utl44ydMFKy + o6uNfUVLEaegW9ryjuvwGKyhzN3jxAk8ZNJift1NaFmvrxWfYdhoeWpVxcMeZJJ1v" =>"address" =>=>"Osaka", "address2" =>"Chuo-ku, Osaka", "address3" =>"Namba 5-1 -60", "building_name" =>"Io 15th floor", "phone_number" =>" 0503187-577 "}, "commit" =>"update", "controller" =>"searches", "action" =>"update", "id" =>"1"} permitted: false>

Supplementary information (FW/tool version, etc.)

ruby '2.6.5'

Search.find (params [: id]) contains the value before the change and cannot be changed.
The params contain the changed values, but I don't know how to write them.

  • Answer # 1

    It is thought that the cause is that the value cannot be retrieved with the strong parameter.


    params.require (: search).permit (: address1,: address2,: address3,: building_name,: phone_number,: postal_code)
    in this way.require (: search)I think you should add.