This file contains hidden or 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
# 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> |
This file contains hidden or 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
# app/views/amp/samples/show.amp.erb | |
# write your HTML for AMP page here. |
This file contains hidden or 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
# 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 |
This file contains hidden or 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
# config/initializers/mime_types.rb | |
Mime::Type.register 'text/html', :amp |
This file contains hidden or 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
optimization: | |
<<: *development |
This file contains hidden or 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
group :optimization do | |
gem 'bullet', '~> 6.1.0' | |
end |
This file contains hidden or 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
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 |
This file contains hidden or 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
gem 'bullet', '~> 6.1.0' |
This file contains hidden or 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 AddSlugToEntries < ActiveRecord::Migration[5.2] | |
def change | |
add_column :entries, :slug, :string | |
add_index :entries, :slug, unique: true | |
end | |
end |
This file contains hidden or 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 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 |