Created
September 3, 2014 08:41
-
-
Save windsochi/86ab6f541445896e65f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CardsController < ApplicationController | |
before_action :find_card, only: [:show, :edit, :update, :destroy] | |
def index | |
@cards = current_user.cards | |
end | |
def new | |
@card = Card.new | |
end | |
def create | |
@card = current_user.cards.new(card_params) | |
if @card.save | |
redirect_to cards_path | |
flash[:notice] = 'Card successed created!' | |
else | |
render 'new' | |
flash[:alert] = 'Failed' | |
end | |
end | |
def show | |
end | |
def edit | |
end | |
def update | |
if @card.update(card_params) | |
redirect_to edit_card_path | |
flash[:notice] = 'Card successed updated!' | |
else | |
render 'edit' | |
end | |
end | |
def destroy | |
@card.destroy | |
redirect_to cards_path, notice: 'Card deleted' | |
end | |
private | |
def card_params | |
params.require(:card).permit(:review_date, :original_text, :translated_text, :user_id, :picture, :remove_picture) | |
end | |
def find_card | |
@card = current_user.cards.find(params[:id]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment