Sha256: ac8cbab5692aace8c6ab2c767c420335aab2d1f7f5a497e15995c9c121c0df5a

Contents?: true

Size: 887 Bytes

Versions: 2

Compression:

Stored size: 887 Bytes

Contents

class EmailsController < ApplicationController
  before_action :set_<%= singular_table_name %>
  before_action :validate_current_password, only: :update

  def edit
  end

  def update
    if @<%= singular_table_name %>.update(<%= "#{singular_table_name}_params" %>)
      redirect_to root_path, notice: "Your email has been changed"
    else
      render :edit, status: :unprocessable_entity
    end
  end

  private
    def set_<%= singular_table_name %>
      @<%= singular_table_name %> = Current.<%= singular_table_name %>
    end

    def <%= "#{singular_table_name}_params" %>
      params.require(:<%= singular_table_name %>).permit(:email)
    end

    def validate_current_password
      unless @<%= singular_table_name %>.authenticate(params[:current_password])
        redirect_to edit_email_path, alert: "The current password you entered is incorrect"
      end
    end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
authentication-zero-2.2.9 lib/generators/authentication/templates/controllers/html/emails_controller.rb.tt
authentication-zero-2.2.8 lib/generators/authentication/templates/controllers/html/emails_controller.rb.tt