Skip to content

Instantly share code, notes, and snippets.

View 123ish's full-sized avatar

123ish LLC 123ish

View GitHub Profile
@123ish
123ish / application.amp.erb
Created July 9, 2020 01:49 — forked from kevinhq/application.amp.erb
Create AMP in Rails powered website - application.amp.erb
# app/views/amp/layouts/application.amp.erb
<!DOCTYPE html>
<html amp lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<!-- add/remove ampproject.org scripts as you need it -->
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>
@123ish
123ish / show.amp.erb
Created July 9, 2020 01:48 — forked from kevinhq/show.amp.erb
Create AMP in Rails powered website - show.amp.erb
# app/views/amp/samples/show.amp.erb
# write your HTML for AMP page here.
@123ish
123ish / samples_controller.rb
Created July 9, 2020 01:47 — forked from kevinhq/samples_controller.rb
Create AMP in Rails powered website - samples_controller.rb
# app/controllers/samples_controller.rb
Class SamplesController
# other existing methods
def show
# your existing codes
respond_to do |format|
format.html
format.amp { render 'amp/samples/show.amp', layout: 'amp/layouts/application' }
end
@123ish
123ish / mime_types.rb
Created July 6, 2020 20:59 — forked from kevinhq/mime_types.rb
Create AMP in Rails powered website - mime_types.rb
# config/initializers/mime_types.rb
Mime::Type.register 'text/html', :amp
@123ish
123ish / webpacker.yml
Last active July 3, 2020 19:14
Update config/webpacker.yml
optimization:
<<: *development
@123ish
123ish / Gemfile
Created July 3, 2020 15:34 — forked from kevinhq/Gemfile
Gemfile with custom environment
group :optimization do
gem 'bullet', '~> 6.1.0'
end
@123ish
123ish / optimization.rb
Created July 3, 2020 15:34 — forked from kevinhq/optimization.rb
Place this on config/environments/optimization.rb
config.after_initialize do
Bullet.enable = true
Bullet.alert = true
Bullet.bullet_logger = true
Bullet.console = true
Bullet.rails_logger = true
Bullet.add_footer = true
end
@123ish
123ish / Gemfile
Created July 3, 2020 15:32 — forked from kevinhq/Gemfile
Optimize Rails app with Bullet - Gemfile
gem 'bullet', '~> 6.1.0'
@123ish
123ish / date_add_slug_to_entries.rb
Created June 27, 2020 21:30
friendly id #db/migrate/date_add_slug_to_entries.rb
class AddSlugToEntries < ActiveRecord::Migration[5.2]
def change
add_column :entries, :slug, :string
add_index :entries, :slug, unique: true
end
end
@123ish
123ish / entries_controller.rb
Last active June 27, 2020 21:21
Friendly ID # /app/controllers/entries_controller.rb
class EntriesController < ApplicationController
before_action :set_entry, only: [:show, :update, :destroy, :edit]
def set_entry
@entry = Entry.find(params[:id])
if !Rails.env.test? && @entry.friendly_id.present? && action_name=='show'
redirect_to action: action_name, id: @entry.friendly_id, status: 301 unless @entry.friendly_id == params[:id]
end
end
emd