Skip to content

Instantly share code, notes, and snippets.

@GeorgeBramus
Created December 15, 2017 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GeorgeBramus/139fd5813b9fa1f130036d5bc006166e to your computer and use it in GitHub Desktop.
Save GeorgeBramus/139fd5813b9fa1f130036d5bc006166e to your computer and use it in GitHub Desktop.
misspelling output
class CheckCardAndUpdate
# ...
def call
card = Card.find(context.card_id)
context.message = if coincides?(card.original_text, context.custom_original_text)
correct_answer(card)
'right'
else
incorrect_answer(card)
context.misspelling = coincides?(card.original_text, context.custom_original_text)
'wrong'
end
end
# ...
private def coincides?(card_original_text, custom_original_text)
DamerauLevenshtein.distance(card_original_text.mb_chars.downcase.to_s, custom_original_text.mb_chars.downcase.to_s) == 0
end
# ...
end
class HomeController < ApplicationController
# ...
def check
result = CheckCardAndUpdate.call(
custom_original_text: params[:original_text],
card_id: params[:id]
)
@misspelling = result.misspelling if result.misspelling
flash[:notice] = result.message
redirect_to action: :index
end
end
/ ...
- if flash[:notice]
#error_explanation class="#{flash[:notice]}"
h2 Результат
ul
li = flash[:notice]
- if @misspelling
= @misspelling
/ форма на главную страницу
/ ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment