class WithdrawablesController

Public Instance Methods

create() click to toggle source

To withdraw money from user account.

# File app/controllers/withdrawables_controller.rb, line 23
def create
  @withdrawable = Withdrawable.new(withdrawable_params.merge(user_id: current_user.id))
  respond_to do |format|
    if @withdrawable.withdraw
      format.js
    else
      format.js {render partial: 'form', replace: 'form#new_withdrawable'}
    end
  end
end
new() click to toggle source

It will show the total amount and withdrawable amount to user and also has withdraw option so that user can withdraw amount.

# File app/controllers/withdrawables_controller.rb, line 8
def new
  if current_user.bank_account.present?
    @withdrawable = Withdrawable.new
    @withdrawable_amount = current_user.withdrawable_amount
    @total_amount = current_user.total_balance
    render layout: false
  else
    @user = current_user
    @user.bank_accounts.build unless @user.bank_accounts.exists?
    @redirect_url = new_withdrawable_path
    render template: 'settings/bank_accounts', layout: false
  end
end