Skip to content

Instantly share code, notes, and snippets.

View bqst's full-sized avatar
:shipit:

Bastien bqst

:shipit:
View GitHub Profile
@bqst
bqst / gist:5006385
Created February 21, 2013 17:17
bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
@bqst
bqst / post.rb
Created March 15, 2018 16:11
app/models/post.rb
# app/models/post.rb
class Post < ApplicationRecord
# friendly url
extend FriendlyId
friendly_id :title, use: :slugged
end
# app/controllers/posts_controller.rb
def show
@post = Post.friendly.find(params[:id])
end
# config/routes.rb
match "/404", to: "errors#not_found", via: :all
match "/422", to: "errors#unacceptable", via: :all
match "/500", to: "errors#internal_server_error", via: :all
# app/controllers/errors_controller.rb
# do not forget to delete public/{404, 422, 500}.html
# rm public/{404, 422, 500}.html
class ErrorsController < ApplicationController
def not_found
render status: 404
end
# config/application.rb
config.exceptions_app = self.routes
# 301 redirect from old URLs
match "/old_path_to_posts/:id", to: redirect("/posts/%{id}s")
# config/meta.yml
meta_title: "SEO & Ruby On Rails"
meta_description: "The 2018 comprehensive guide on SEO in Rails"
meta_image: "logo.png" # Une image dans votre dossier app/assets/images/
twitter_account: "@RevancheSites"
# config/initializers/default_meta.rb
# Initialize default meta tags.
DEFAULT_META = YAML.load_file(Rails.root.join("config/meta.yml"))
# app/helpers/meta_tags_helper.rb
module MetaTagsHelper
def meta_title
content_for?(:meta_title) ? content_for(:meta_title) : DEFAULT_META["meta_title"]
end
def meta_description
content_for?(:meta_description) ? content_for(:meta_description) : DEFAULT_META["meta_description"]
end