Advertisement
VladikOtez

Interactor

May 17th, 2017
1,112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.69 KB | None | 0 0
  1. class ReviewCard
  2.   include Interactor
  3.  
  4.   def call
  5.     id          =             context.id
  6.     translation =    context.translation
  7.     card        =           Card.find(id)
  8.     answer      = card.check_translation translation
  9.     answer ? context.message = 'Correct' :
  10.              context.message = 'Incorrect'
  11.   end
  12. end
  13. --------------------------------------------------------------------------
  14. def review_card
  15.     result = ReviewCard.call(
  16.     id: params[:card_id],
  17.     translation: trainer_params[:translation]
  18.     )
  19.     @card = result.card
  20.     if result.success?
  21.       @card.refresh_review_date
  22.       redirect_back
  23.     else
  24.       redirect_to trainer_index_path
  25.     end
  26.   end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement