Class: Iro::PursesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/iro/purses_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#home, #schwab_sync

Instance Method Details

#createObject



6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/iro/purses_controller.rb', line 6

def create
  @purse = Iro::Purse.new params[:purse].permit!
  authorize! :create, @purse
  if @purse.save
    ;
  else
    flash_alert @purse
  end
  redirect_to action: :index
end

#destroyObject



17
18
19
20
21
22
# File 'app/controllers/iro/purses_controller.rb', line 17

def destroy
  @purse = Iro::Purse.find(params[:id])
  authorize! :destroy, @purse
  @purse.destroy
  redirect_to action: :index, notice: 'Purse was successfully destroyed.'
end

#editObject



24
25
26
27
# File 'app/controllers/iro/purses_controller.rb', line 24

def edit
  @purse = Iro::Purse.find(params[:id])
  authorize! :edit, @purse
end

#indexObject



29
30
31
32
# File 'app/controllers/iro/purses_controller.rb', line 29

def index
  @purses = Iro::Purse.all
  authorize! :index, Iro::Purse
end

#showObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/iro/purses_controller.rb', line 34

def show
  @purse = Iro::Purse.find(params[:id])
  authorize! :show, @purse


  @positions = @purse.positions.where( status: 'active' ).includes( :strategy
    ).order( expires_on: :asc, ticker: :desc, long_or_short: :asc, inner_strike: :asc )


  @unit      = @purse.unit # 12  ## pixels per dollar
  @height    = @purse.height # 100  ## pixels
  @n_dollars = 100 ## dollars to each side of origin

  calc_summary

  render params[:template]
end

#updateObject



52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/iro/purses_controller.rb', line 52

def update
  @purse = Iro::Purse.find(params[:id])
  authorize! :update, @purse
  if @purse.update params[:purse].permit!
    flash[:notice] = 'ok'
    redirect_to request.referrer # purse_path(@purse)
  else
    flash_alert @purse
    render :edit
  end
end