Skip to content

Instantly share code, notes, and snippets.

@rebelweb
rebelweb / thing.rb
Last active May 1, 2018 18:20
raisl callback example
# frozen_String_literal: true
class Thing < ApplicationRecord
validates :name, presence: true
# can use before_create, before_save, before_update, after_save, after_create,
# after_update, before_validation, after_validation
# also accepts if/unless
before_save :set_bool #, if: proc { |thing| thing.name == 'TEST' }
@rebelweb
rebelweb / application.html.erb
Created December 8, 2017 13:22
Webpacker / Bootstrap Config
<%# /app/views/layouts/application.html.erb %>
<!DOCTYPE html>
<html>
<head>
<title>RyancondronPhotography</title>
<%= csrf_meta_tags %>
<%= stylesheet_pack_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
@rebelweb
rebelweb / .gitlab-ci.yml
Created August 2, 2017 17:36
Gitlab Ci for Rails with Docker
stages:
- test
- build
variables:
DB_HOST: postgres
DB_PASS: postgres
DB_USER: postgres
brakeman:
@rebelweb
rebelweb / notification_type.rb
Last active July 19, 2017 23:47
Basic Object
class NotificationType
attr_accessor :id, :load_id
def initialize(id, load_id)
self.id = id
self.load_id = load_id
check_valid_id
end
def description
@rebelweb
rebelweb / application_decorator.rb
Created June 23, 2017 15:14
Decorator using simple delegator that follows most of draper syntax
require 'delegate'
class ApplicationDecorator < SimpleDelegator
def self.decorate(instance)
return nil if instance.blank?
new instance
end
def self.decorate_collection(collection)
return [] if collection.nil? || collection.length.zero?
#!/bin/bash
#
# Copyright:: Copyright (c) 2015 Gitlab.com
# Copyright:: Copyright (c) 2016 Amusement SMART, LLC
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
@rebelweb
rebelweb / atom_packages.txt
Created December 7, 2015 15:24
Atom Configuration
packages:
- advanced-open-file
- color-picker
- emmet
- erb-helper
- file-icons
- filesize
- git-plus
- markdown-preview-plus
- minimap
<%= form_for @playlist do |f| %>
<%= f.text_field :name, placeholder: 'Name' %>
<%= f.text_area :description %>
<%= f.date_field :date_in %>
<%= f.date_field :date_out %>
<%= f.fields_for :media_files do |ff| %>
<%= ff.collection_select :media_file_id, MediaFile.all, :id, :name, {}, {} %>
<%= ff.select :position, options_for_select((1..50).step(1) {}
<%= ff.link_to_remove 'Remove from Playlist' %>
<% end %>
@rebelweb
rebelweb / archive.rb
Last active August 29, 2015 14:13
Simple Archive for Rails
class Archive < ActiveRecord::Base
#model will be read only!
def self.posts
Post.where('published = ? and published_date >= ? and published_date <= ?', true, Date.civil(a.year, a.month, 1), Date.civil(a.year, a.month, -1))
end
end
@rebelweb
rebelweb / rails_helper.rb
Last active May 14, 2021 01:13
Brakeman/RSpec Inegration
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'brakeman'
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.use_transactional_fixtures = true