Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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