密码未在 ruby 中更新

问题描述 投票:0回答:0

我创建了一个允许用户更改密码的页面,但更新查询不起作用

password_cotroller:

before_action :require_no_authentication, only: [:new, :create]
  def edit
    
  end

  def update
    puts "Params: #{password_params.inspect}"
     if current_user.update_with_password(password_params)
        redirect_to profile_path, notice: "Password updated successfully."
    else
      flash[:alert] = "Password not updated successfully."
      render :edit
    end
  end

  def password_params
    params.require(:user).permit(:password, :password_confirmation)
  end

包含表格的页面:

<%= form_for(current_user, url: user_password_path, html: { method: :put,class: "form-horizontal"}) do |f| %>

                    
                                <div class="form-group mb-3  col-sm-15">
                                  <% if @minimum_password_length %>
                                  <em>(<%= @minimum_password_length %> character in minimum)</em>
                                  <% end %><br />
                                  <%= f.password_field :password, autocomplete: "off", class: "form-control border-0 shadow-sm px-4 text-primary", placeholder: "password",type: "password" %>
                                </div>
                                <div class="form-group mb-3  col-sm-15">
                                
                                  <%= f.password_field :password_confirmation, autocomplete: "off", class: "form-control  border-0 shadow-sm px-4 text-primary", placeholder: "password confirmation",type: "password" %>
                                </div>
                                <button type="submit" style="background-color: #7db942;color:white;" class="btn btn-block text-uppercase mb-2 rounded-pill shadow-sm">Change password</button>
                            </form>
                        </div>
                    </div>
                </div><!-- End -->

            </div>

我尝试使用 put 和 patch 方法,但同样的问题

这是我终端机里的东西:

Started PATCH "/users/password" for ::1 at 2023-04-24 23:46:04 +0100
Processing by Users::PasswordsController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"3IZjkoOc0bZXOcdy79rHAGZ6aFXI2GqXhL5gKtRH8tRx0/a8LqEoDCCz8LWU23+83EobHJi1kWr/ysFlzhvrXg==", "user"=>{"password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}}
Params: <ActionController::Parameters {"password"=>"rahma", "password_confirmation"=>"rahma"} permitted: true>
  User Load (0.6ms)  SELECT  `users`.* FROM `users` WHERE `users`.`id` = 8 ORDER BY `users`.`id` ASC LIMIT 1
  Rendering users/passwords/edit.html.erb within layouts/application
  Rendered users/passwords/edit.html.erb within layouts/application (1.3ms)
[Webpacker] Everything's up-to-date. Nothing to do
  Rendered shared/_upper_nav.html.erb (0.5ms)
Completed 200 OK in 281ms (Views: 14.1ms | ActiveRecord: 0.6ms)

这是我第一个使用 ruby 的项目,所以我搞不懂

ruby-on-rails ruby ubuntu edit
© www.soinside.com 2019 - 2024. All rights reserved.