secret
Created

fontcontroller1

  • Download Gist
fonts_controller1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
class FontsController < ApplicationController
load_and_authorize_resource
#before_action :set_font, only: [:show, :edit, :update, :destroy]
 
def index
@fonts = Font.find_with_reputation(:likes, :all, {:order => 'likes desc'})
end
 
def show
end
 
def self.most_liked
find_with_reputation(:likes, :all, {:order => 'likes DESC'})
end
 
def like
value = params[:type] == "up" ? 1 : -1
@font = Font.find(params[:id])
@font.add_or_update_evaluation(:likes, value, current_user)
redirect_to :back, notice: "Thanks for voting!"
end
 
def new
@font = current_user.fonts.build
# if current_user = nil?
# redirect_to root_path
# end
end
 
 
def create
@font = current_user.fonts.build(font_params)
 
 
respond_to do |format|
if @font.save
format.html { redirect_to @font, notice: 'Font was successfully created.' }
format.json { render action: 'show', status: :created, location: @font }
else
format.html { render action: 'new' }
format.json { render json: @font.errors, status: :unprocessable_entity }
end
end
end
 
 
def update
respond_to do |format|
if @font.update(font_params)
format.html { redirect_to @font, notice: 'Font was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @font.errors, status: :unprocessable_entity }
end
end
end
 
 
def destroy
@font.destroy
respond_to do |format|
format.html { redirect_to fonts_url }
format.json { head :no_content }
end
end
 
private
 
def screenshot_params
params.require(:screenshot).permit(:title, :assets_attributes => [:filename, :id, :screenshot_id])
end
 
def font_params
params.require(:font).permit(:fontnames, :description, :html, :css, :name)
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.