Class: Bible270::ReadersController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Bible270::ReadersController
- Defined in:
- app/controllers/bible270/readers_controller.rb
Instance Method Summary collapse
- #clear_start_date ⇒ Object
- #index ⇒ Object
-
#progress ⇒ Object
The reader's own progress.
- #show ⇒ Object
- #update_start_date ⇒ Object
Instance Method Details
#clear_start_date ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'app/controllers/bible270/readers_controller.rb', line 46 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 |
#index ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'app/controllers/bible270/readers_controller.rb', line 5 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.total_parts(day) } # Progress first, then by name — the same name ordering the admin list uses. @readers.sort_by! { |r| [-@days_completed[r.id], r.sort_name] } end |
#progress ⇒ Object
The reader's own progress. Deliberately open to visitors: the panel shows an invitation to sign in rather than an error, and every value it needs comes from the reader it is given.
17 18 19 20 21 |
# File 'app/controllers/bible270/readers_controller.rb', line 17 def progress @reader = current_reader # An empty relation rather than nil, so the view needs no safe navigation. @recent_comments = @reader ? @reader.comments.recent.limit(5) : Comment.none end |
#show ⇒ Object
23 24 25 26 27 28 29 |
# File 'app/controllers/bible270/readers_controller.rb', line 23 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_date ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/bible270/readers_controller.rb', line 31 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 |