Skip to content

Instantly share code, notes, and snippets.

View yoonwaiyan's full-sized avatar
🏠
Working from home

Wai Yan Yoon yoonwaiyan

🏠
Working from home
View GitHub Profile
.video { position: relative; padding-bottom: 56.25%; /* 16:9 */ height: 0; }
.video img { position: absolute; display: block; top: 0; left: 0; width: 100%; height: 100%; z-index: 20; cursor: pointer; }
.video:after { content: ""; position: absolute; display: block;
background: url(play-button.png) no-repeat 0 0;
top: 45%; left: 45%; width: 46px; height: 36px; z-index: 30; cursor: pointer; }
.video iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
/* image poster clicked, player class added using js */
.video.player img { display: none; }
.video.player:after { display: none; }
@yoonwaiyan
yoonwaiyan / status_tag.css.scss
Created January 7, 2015 07:11
Status Tag CSS extracted from ActiveAdmin. Can be applied in any scss with "status_tag" class with the appropriate class name for the colors.
.status_tag {
background: darken(#cacaca, 15%);
color: #fff;
text-transform: uppercase;
letter-spacing: 0.15em;
padding: 3px 5px 2px 5px;
font-size: 0.8em;
&.ok, &.published, &.complete, &.completed, &.green { background: #8daa92; }
&.warn, &.warning, &.orange { background: #e29b20; }
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
@yoonwaiyan
yoonwaiyan / _footer.html.haml
Last active August 29, 2015 14:19
Custom footer for Active Admin
@yoonwaiyan
yoonwaiyan / application_controller.rb
Created May 20, 2015 08:28
Handling routing error in Rails 4
def routing_error
respond_to do |format|
format.html { render :file => "#{Rails.root}/public/404", :layout => false, :status => :not_found }
format.xml { head :not_found }
format.any { head :not_found }
end
end
@yoonwaiyan
yoonwaiyan / books_controller.rb
Created May 21, 2015 13:14
Controller Scaffold
class BookController < ApplicationController
def list
@books = Book.find(:all)
end
def show
@book = Book.find(params[:id])
end
def new
@book = Book.new
@subjects = Subject.find(:all)
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
@yoonwaiyan
yoonwaiyan / application.js
Created June 22, 2015 06:53
Bootstrap 3 with jQuery Validation
$.validator.setDefaults({
errorElement: "span",
errorClass: "help-block",
highlight: function (element, errorClass, validClass) {
$(element).closest('.form-group').addClass('has-error');
},
unhighlight: function (element, errorClass, validClass) {
$(element).closest('.form-group').removeClass('has-error');
},
errorPlacement: function (error, element) {
@yoonwaiyan
yoonwaiyan / blank_slate.rb
Created July 31, 2015 14:18
Blank slate monkey patch
require 'active_admin/helpers/collection'
module ActiveAdmin
module Views
module Pages
class Index < Base
protected
def render_blank_slate
blank_slate_content = I18n.t("active_admin.blank_slate.content", resource_name: active_admin_config.plural_resource_label)
insert_tag(view_factory.blank_slate, blank_slate_content)