Skip to content

Instantly share code, notes, and snippets.

@leemcalilly
Created July 31, 2018 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leemcalilly/f9936be771d5bad500ee42ba53babd7a to your computer and use it in GitHub Desktop.
Save leemcalilly/f9936be771d5bad500ee42ba53babd7a to your computer and use it in GitHub Desktop.
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