Class: BeesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- BeesController
- Defined in:
- app/controllers/bees_controller.rb
Overview
Handles redirects of spelling bee
Instance Method Summary collapse
-
#edit ⇒ Bee
This method sets the bee object to be edited.
-
#index ⇒ Array<Bee>
This method shows the seven games from tomorrow.
-
#play ⇒ nil
This method is the starting point of the game.
-
#submit_guess ⇒ nil
This method is the handler of game logic.
-
#update ⇒ Bee
This method updates the bee object.
Instance Method Details
#edit ⇒ Bee
This method sets the bee object to be edited
15 16 17 18 19 |
# File 'app/controllers/bees_controller.rb', line 15 def edit @bee = Bee.find(params[:id]) @valid_words = WordsService.words(@bee.letters) @total_score = @valid_words.reduce(0) { |sum, word| sum + (word.length - 3) } end |
#index ⇒ Array<Bee>
This method shows the seven games from tomorrow
6 7 8 9 |
# File 'app/controllers/bees_controller.rb', line 6 def index BeesService.set_week_bee() @bees = Bee.where(play_date: Date.tomorrow..Date.tomorrow + 6).order(:play_date) end |
#play ⇒ nil
This method is the starting point of the game
40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/bees_controller.rb', line 40 def play session[:sbwords] ||= [] session[:sbscore] ||= 0 BeesService.set_day_bee() @bee = Bee.find_by(play_date: Date.today) @aesthetic = Aesthetic.find_by(game_id: Game.find_by(name: "Spelling Bee").id) render "spellingbee" end |
#submit_guess ⇒ nil
This method is the handler of game logic
54 55 56 57 58 59 |
# File 'app/controllers/bees_controller.rb', line 54 def submit_guess @bee = Bee.find_by(play_date: Date.today) session[:sbwords], session[:sbscore], flash[:sb] = BeesService.guess(params[:sbword], session[:sbwords], session[:sbscore]) update_stats(session[:sbscore]) redirect_to bees_play_path end |
#update ⇒ Bee
This method updates the bee object
26 27 28 29 30 31 32 33 34 35 |
# File 'app/controllers/bees_controller.rb', line 26 def update @bee = Bee.find(params[:id]) params[:bee][:ranks] = JSON.parse(params[:bee][:ranks]) if @bee.update(bee_params) redirect_to edit_bee_path(@bee), notice: "Spelling Bee for #{@bee.play_date.strftime("%B %d")} updated successfully!" else redirect_to edit_bee_path(@bee), alert: "Invalid update" end end |