Created
July 31, 2018 04:31
-
-
Save leemcalilly/45609209623b147d388717af814ed4bf 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 QuotesController < ApplicationController | |
before_action :set_quote, only: [:show] | |
before_action :require_login | |
skip_before_action :require_login, only: [:index, :show] | |
def show | |
end | |
def new | |
@quote = Quote.new | |
authorize @quote | |
end | |
def create | |
@quote = current_user.quotes.build(quote_params) | |
authorize @quote | |
if @quote.save | |
flash[:success] = "Quote created!" | |
redirect_to @quote | |
else | |
render :new | |
end | |
end | |
private | |
def quote_params | |
params.require(:quote).permit(:text, :source, :topic_id, :speaker_id, | |
:genre_id) | |
end | |
def set_quote | |
@quote = Quote.find(params[:id]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment