Class: Bible270::ReadersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/bible270/readers_controller.rb

Instance Method Summary collapse

Instance Method Details

#clear_start_dateObject



35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/bible270/readers_controller.rb', line 35

def clear_start_date
  return unless require_reader!

  if Bible270.config.allow_reader_start_date
    current_reader.clear_start_date!
    redirect_to root_path, notice: "Start date cleared — the plan is now undated for you."
  else
    redirect_to root_path, alert: "The start date is set for the whole community."
  end
end

#indexObject



4
5
6
7
8
9
10
# File 'app/controllers/bible270/readers_controller.rb', line 4

def index
  @readers = Reader.all.to_a
  counts = Checkoff.group(:reader_id, :day).count
  @days_completed = Hash.new(0)
  counts.each { |(rid, day), n| @days_completed[rid] += 1 if n >= Plan.required_track_count(day) }
  @readers.sort_by! { |r| [-@days_completed[r.id], r.display_name.to_s] }
end

#showObject



12
13
14
15
16
17
18
# File 'app/controllers/bible270/readers_controller.rb', line 12

def show
  @reader = Reader.find_by(id: params[:id])
  redirect_to(community_path, alert: "Reader not found.") and return unless @reader

  @days_completed = @reader.days_completed
  @recent_comments = @reader.comments.recent.limit(20)
end

#update_start_dateObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/bible270/readers_controller.rb', line 20

def update_start_date
  return unless require_reader!

  unless Bible270.config.allow_reader_start_date
    redirect_to(root_path, alert: "The start date is set for the whole community.") and return
  end

  if current_reader.update_start_date!(params[:start_date])
    redirect_to root_path,
                notice: "Start date set to #{current_reader.started_on.strftime('%B %-d, %Y')}."
  else
    redirect_to root_path, alert: "That doesn't look like a valid date."
  end
end