Skip to content

Instantly share code, notes, and snippets.

module TenantServices
class AccessService
def initialize(params)
@site = params[:site]
@customer = params[:customer]
@user = params[:user]
@record = params[:record]
@feature = params[:feature]
class GiftCard < ApplicationRecord
belongs_to :site
belongs_to :subscription_plan, optional: true
acts_as_tenant :site
include ProductConcern
include ImageUploader[:image]
enum status: { draft:0, published:1}
@bearded-avenger
bearded-avenger / do_something.rb
Created July 22, 2020 17:16
Simple Role based Authorization for Ruby on Rails
# Roles Table
Role.create([{name:'admin'},{name:'staff'}])
# Users Roles Table
UserRole.create(user: User.find_by_username('corndog'), role: Role.find_by_name('admin'))
# User Model
class User < ApplicationRecord
def role?(role)
role.kind_of?(Array) ? role.map { |role| has_role?(role) }.any? : has_role?(role)
@bearded-avenger
bearded-avenger / add_remove.html.erb
Last active July 2, 2020 15:50
Bookmarking in Rails
# In a View
<%= render 'bookmarks/add_remove', record: @lesson %>
# The Partial
<% if current_customer && current_customer.bookmarked_content?(record) %>
<%= button_to bookmark_path(current_customer.bookmark_for_content(record), bookmarkable_type:record.class.name, bookmarkable_id:record.id), method: :delete, class:'btn btn-sm btn-light box-shadow', form_class:'add-remove-bookmark', data:{disable_with:'Removing...'}, remote: true do %>
<%= ms_icon('minus-circle', title:'Unsave This') %>
<% end %>
<% else %>
<%= button_to bookmarks_path(bookmarkable_type:record.class.name, bookmarkable_id:record.id), method: :post, class:'btn btn-sm btn-light box-shadow', form_class:'add-remove-bookmark', data:{disable_with:'Adding...'}, remote: true do %>
@bearded-avenger
bearded-avenger / author-network-posts.php
Created November 7, 2014 19:36
Return a list of posts by a specific author no matter the site on the multisite network
/**
*
* Return a list of posts by a specific author no matter the site on the multisite network
*
* @param $userid int id of a user
* @param $limit int number of results to return
*
*
*/
function get_user_posts_on_network( $userid = 0, $limit = 9 ) {
@bearded-avenger
bearded-avenger / gist:e9d7ec26b0675bbc208a
Created September 16, 2014 16:24
Full Screen Components in Make
/*
- .aesop-on-THEMENAME is a class that aesop applies to themes
- this breaks the width that sets on main column
- .single targeting only single posts
*/
.aesop-on-make.single .container {
max-width:100%;
padding-left:0;
padding-right:0;
}
module Checkups::Notify
require 'slack-notify'
class Dispatch
def initialize(params)
@message = params[:message]
@room = params[:room] || '#web-dev_events'
@botname = params[:botname] || 'EDU Bot'
@bearded-avenger
bearded-avenger / gist:f478639cbf0847c48230
Last active February 27, 2016 09:32
Aesop Story Engine - Full Screen Components in Genesis
.aesop-on-genesis .site-inner{
max-width:100%;
}
.aesop-on-genesis .entry {
padding-left:0;
padding-right:0;
}
.aesop-on-genesis .entry-header,
.aesop-on-genesis .entry-content > *:not(.aesop-component) {
width: 100%;
@bearded-avenger
bearded-avenger / edd-settings-example.php
Last active January 15, 2016 21:03
This sample class shows how 3rd party devs can add a tab to Easy Digital Downloads wp-admin settings tab, along with how to use the EDD Settings API. NOW AS A REPO https://github.com/bearded-avenger/edd-settings-api-sample
<?php
class sampleClass {
function __construct() {
add_filter( 'edd_settings_tabs', array($this,'test_tab' ));
add_action('admin_init', array($this,'edd_register_settings_test'));
}
@bearded-avenger
bearded-avenger / index.html
Last active January 2, 2016 23:29
CrowdHoster Campaign Theme
<!-- Start Aesop Crowdhoster -->
<blockquote>
<p>...one of the most beautiful tools for Wordpress that I&#39;ve seen in a long time.</p>
<cite>- <a href="http://wptavern.com/aesop-story-engine-an-open-source-wordpress-plugin-for-storytelling">WP Tavern</a></cite></blockquote>
<blockquote>
<p>...a potentially seismic shift in content creation and the biggest thing to hit WP for ages.</p>
<cite>- <a href="http://wptavern.com/aesop-story-engine-an-open-source-wordpress-plugin-for-storytelling#comment-50657">Chris Knowles</a></cite></blockquote>
<blockquote>