Home>

I'm stumbling with an error while updating user information using devise in Rails ...

Error statement

An error is output in binding.pry to update of refistrations_controller.rb.

** registrations_controller.rb **
  def update
    super
    binding.pry
  end

Check the error statement on the terminal

[2] pry (#<Users :: RegistrationsController>)>@ user.update
ArgumentError: wrong number of arguments (given 0, expected 1)
from /Users/eleaco/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.4/lib/active_record/persistence.rb:616:in ʻupdate'

I need one argument that I often see, but it is said that it is not enough ...

code

I will look from the view

** registrations>edit.html.erb **<% = form_with model: @user, url: user_registration_path, local: true do | f |%><% = render "devise/shared/error_messages", resource: resource%>      <% = f.text_area: profile, class:'edit-profile'%>

registrarions_controller.rb

** registrations_controller.rb **
class Users :: RegistrationsController<Devise :: RegistrationsController
before_action: configure_account_update_parameters, only: [: update]
 def update
    # @ user.update (account_update_params) The reason I deleted it here is before_action
Because it calls the #configure_account_update_parameters method.
 end
protected
  def configure_account_update_parameters
    devise_parameter_sanitizer.permit (: account_update, keys: [: profile])
  end

application_controller.rb

** application_controller.rb **
class ApplicationController</pre>
<strong>Codes added by everyone's point</strong>
<pre><code>** registrations_controller.rb **
  def update
    super
    binding.pry
  end


Check what's inside in binding.pry

[2] pry (#<Users :: RegistrationsController>)>@user
=>#<User id: 2, nickname: "gest", email: "gest @ gest", profile: "This is a self-introduction", created_at: "2020-11-01 00:55:52", updated_at: "2020-11-01 00:55:52">


The self-introduction text is in @user ... but cannot be saved ...

Added @ user.errors.messages in binding.pry

[1] pry (#<Users :: RegistrationsController>)>@ user.update
ArgumentError: wrong number of arguments (given 0, expected 1)
from /Users/eleaco/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.4/lib/active_record/persistence.rb:616:in ʻupdate'
[2] pry (#<Users :: RegistrationsController>)>@ user.errors.messages
=>{: password =>["can't be blank", "is invalid"],

 : current_password =>["can't be blank"],

 I wrote it in: profile =>[]} # profile, but it seems empty
[3] pry (#<Users :: RegistrationsController>)>

user.rb

devise: database_authenticatable,: registerable,
         : recoverable,: rememberable,: validatable
  with_options presence: true do | i |
    i.validates: nickname
    i.validates: email
    i.validates: password
    i.validates: encrypted_password
    #Profile is not described! !! Is it here ...?
  end

schema.rb

#This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
#This file is the source Rails uses to define your schema when running `rails
# db: schema: load`. When creating a new database, `rails db: schema: load` tends to
# be faster and is potentially less error prone than running all of your
#migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord :: Schema.define (version: 2020_10_23_085817) do
  create_table "active_storage_attachments", options: "ENGINE = InnoDB DEFAULT CHARSET = utf8", force:: cascade do | t |
    t.string "name", null: false
    t.string "record_type", null: false
    t.bigint "record_id", null: false
    t.bigint "blob_id", null: false
    t.datetime "created_at", null: false
    t.index ["blob_id"],

 name: "index_active_storage_attachments_on_blob_id"
    t.index ["record_type", "record_id", "name", "blob_id"],

 name: "index_active_storage_attachments_uniqueness", unique: true
  end
  create_table "active_storage_blobs", options: "ENGINE = InnoDB DEFAULT CHARSET = utf8", force:: cascade do | t |
    t.string "key", null: false
    t.string "filename", null: false
    t.string "content_type"
    t.text "metadata"
    t.bigint "byte_size", null: false
    t.string "checksum", null: false
    t.datetime "created_at", null: falset.index ["key"],

 name: "index_active_storage_blobs_on_key", unique: true
  end
  create_table "comments", options: "ENGINE = InnoDB DEFAULT CHARSET = utf8", force :: cascade do | t |
    t.integer "user_id", null: false
    t.integer "photo_id", null: false
    t.text "text"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
  end
  create_table "favorites", options: "ENGINE = InnoDB DEFAULT CHARSET = utf8", force :: cascade do | t |
    t.integer "user_id", null: false
    t.integer "photo_id", null: false
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
  end
  create_table "photos", options: "ENGINE = InnoDB DEFAULT CHARSET = utf8", force :: cascade do | t |
    t.text "explanation", null: false
    t.string "title", null: false
    t.integer "user_id", null: false
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
  end
  create_table "relationships", options: "ENGINE = InnoDB DEFAULT CHARSET = utf8", force:: cascade do | t |
    t.integer "following_id", null: false
    t.integer "follower_id", null: false
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.index ["follower_id", "following_id"],

 name: "index_relationships_on_follower_id_and_following_id", unique: true
  end
  create_table "users", options: "ENGINE = InnoDB DEFAULT CHARSET = utf8", force :: cascade do | t |
    t.string "nickname", null: false
    t.string "email", default: "", null: false
    t.string "encrypted_password", default: "", null: false
    t.text "profile"
    t.string "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.index ["email"],

 name: "index_users_on_email", unique: true
    t.index ["reset_password_token"],

 name: "index_users_on_reset_password_token", unique: true
  end
  add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
end

The code looks like this
Please lend us your help!

  • Answer # 1

    password is always required. I think you need to register and change your password.
    So remove it from this blockon :: createLet's add an option.
    : current_password is also required. Please refer to here.
    What is the profile error? .. ..
    Show schema