Class: WordlesController

Inherits:
ApplicationController show all
Includes:
WordlesHelper
Defined in:
app/controllers/wordles_controller.rb

Constant Summary

Constants included from WordlesHelper

WordlesHelper::ALLOWED_GUESSES

Instance Method Summary collapse

Methods included from WordlesHelper

#check_word, #fetch_todays_word, #initialize_guess_session, #make_guess, #reset_game_session, #validate_guess

Instance Method Details

#createObject

POST /wordles or /wordles.json



59
60
61
62
63
64
65
66
# File 'app/controllers/wordles_controller.rb', line 59

def create
  @wordle = Wordle.new(wordle_params)
  if @wordle.save
    redirect_to wordle_path(@wordle), notice: "#{@wordle.word} for date #{@wordle.play_date} was successfully created."
  else
    render :new
  end
end

#destroyObject

DELETE /wordles/1 or /wordles/1.json



79
80
81
82
83
# File 'app/controllers/wordles_controller.rb', line 79

def destroy
  @wordle = Wordle.find(params[:id])
  @wordle.destroy
  redirect_to wordles_path, notice: "Wordle #{@wordle.word} for date #{@wordle.play_date} deleted."
end

#editObject

Deprecated.

no use

GET /wordles/1/edit



55
56
# File 'app/controllers/wordles_controller.rb', line 55

def edit
end

#indexObject

GET /wordles or /wordles.json

Parameters:

  • sort (String)

    Specifies the field to sort results by

  • asc (String)

    Specifies the order in which to sort results. true for ASC and false for DESC



29
30
31
32
33
34
35
36
37
# File 'app/controllers/wordles_controller.rb', line 29

def index
  sort_field = params[:sort]
  asc = params[:asc] =~ /^true$/

  if !sort_field.nil? && asc then @wordles = Wordle.order(sort_field)
  elsif !sort_field.nil? then @wordles = Wordle.order(format("%s DESC", sort_field))
  else @wordles = Wordle.order(format("%s DESC", :play_date))
  end
end

#newObject

GET /wordles/new



45
46
47
48
49
50
51
# File 'app/controllers/wordles_controller.rb', line 45

def new
  if Role.exists?(user_id: session[:user_id], role: "Puzzle Setter")
    @wordle = Wordle.new
  else
    redirect_to wordles_play_path
  end
end

#playObject

Play: /wordles/play



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/wordles_controller.rb', line 11

def play
  @aesthetic = Aesthetic.find_by(game_id: Game.find_by(name: "Wordle").id)
  @definition = WordsService.define(@wordle.word)
  params[:game_id] ||= 2
  session[:wordle_alphabet_used] ||= []
  session[:wordle_words_guessed] ||= []

  if params[:reset]
    reset_game_session(@wordle)
  elsif params[:guess]
    make_guess(params[:guess])
  end
end

#showObject

Deprecated.

no use

GET /wordles/1 or /wordles/1.json



41
42
# File 'app/controllers/wordles_controller.rb', line 41

def show
end

#updateObject

PATCH /wordles/1 or /wordles/1.json



69
70
71
72
73
74
75
76
# File 'app/controllers/wordles_controller.rb', line 69

def update
  @wordle = Wordle.find(params[:id])
  if @wordle.update(wordle_params)
    redirect_to wordle_path(@wordle), notice: "#{@wordle.word} for date #{@wordle.play_date} was successfully updated."
  else
    render :edit
  end
end