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
def address_params
    params.require (: address) .permit (: name,: post_code,: address)

     Delivery address 
  <% = form_with (model: @address, url: addresses_path (@address)) do | f |%>
      <% = f.label: Zip Code%>
      <% = f.text_field: post_code%>
      <% = f.label: Address%>
      <% = f.text_field: address%>
      <% = f.label: Name%>
      <% = f.text_field: name%>
      <% = 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
scope module :: customers do
    resources: addresses, except: [: new,: show]
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

  • 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