Home>

I'm creating a simple site with Ruby on Rails, and I want to be able to register information such as member addresses in the Address table separately from the member table.

NoMethodError (undefined method `permit'for" form input value ": String): I would like to ask you to teach me because the error is occurring and the cause is unknown.

NoMethodError (undefined method `permit'for" form input value ": String):
app/controllers/customers/addresses_controller.rb: 22: in `address_params'
app/controllers/customers/addresses_controller.rb: 6: in `create'
Corresponding source code
def create
    @address = Address.new (address_params)
    @ address.save
    rediect_to addresses_path
  end
private
def address_params
    params.require (: address) .permit (: name,: post_code,: address)
end

  
     Delivery address 
  <% = form_with (model: @address, url: addresses_path (@address)) do | f |%>
      
      <% = f.label: Zip Code%>
      <br>
      <% = f.text_field: post_code%>
      
    <br>
      
      <% = f.label: Address%>
      <br>
      <% = f.text_field: address%>
      
    <br>
      
      <% = f.label: Name%>
      <br>
      <% = f.text_field: name%>
      
    <br>
      
      <% = f.submit'submit'%>
      
  <% end%>
  
create_table "addresses", force:: cascade do | t |
    t.integer "customer_id", null: false
    t.string "name", null: false
    t.string "post_code", null: false
    t.string "address", null: false
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end
scope module :: customers do
    resources: addresses, except: [: new,: show]
end
What I tried

I wondered if the column name was wrong and confirmed it, but there seemed to be no problem.
I also confirmed spelling mistakes, but there were no problems.

Supplementary information (FW/tool version, etc.)

Rails -v 5.2.4.4

  • Answer # 1

    Probably because the contents of params are not posted.
    I'm sorry if I made a mistake.

    This seems to fly the data to the controller, so
    Is there a problem with params or params.require (: address)?
    I think it's probably the latter.
    Please check the inside of params once with binding.pry etc.

    Also, even if this error is resolved, you may still get an error at @ address.save.
    Because there is no customer_id.

    How is it?

Related articles