Advertisement
VladikOtez

Issue#1 Controller

May 17th, 2017
1,153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.73 KB | None | 0 0
  1. class TrainerController < ApplicationController
  2.  # before_action :find_card, only: [:review_card]
  3.   def index
  4.     @card = Card.needs_review.sample
  5.     unless @card
  6.       flash[:notice] = "Congrats. U solved add"
  7.       redirect_to root_path
  8.     end
  9.     respond_to do |format|
  10.       format.html
  11.       format.js
  12.     end
  13.   end
  14.   def review_card
  15.     result = ReviewCard.call(
  16.         translation: trainer_params[:translation]
  17.     )
  18.     @card = result.card
  19.     if result.success?
  20.       redirect_to trainer_index_path
  21.     else
  22.       redirect_to review_card_path(id: @card.id)
  23.     end
  24.   end
  25.   protected
  26. # def find_card
  27.  #   @card = Card.find(params[:card_id])
  28.   #end
  29.   def trainer_params
  30.     params.permit(:translation)
  31.   end
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement